美文网首页
数据库连接池检查 - Springboot项目

数据库连接池检查 - Springboot项目

作者: 筱书专栏 | 来源:发表于2019-02-22 14:51 被阅读0次

有时会遇到一个springboot工程数据库连接断掉的情况。为避免该问题发生,我们可以加上数据库连接池检查。

解决方案

  • 加一个autoReconnection属性 ( 不推荐这种方法了 )

    spring.datasource.url = jdbc:mysql://localhost:3306/xxx?characterEncoding=UTF-8&autoReconnect=true
    
    The use of this feature is not recommended, because it has side effects related to session state and
    data consistency when applications don't handle SQLExceptions properly, and is only designed to be used
    when you are unable to configure your application to handle SQLExceptions resulting from dead and 
    stale connections properly.
    
  • 加上空闲检查配置

    spring.datasource.tomcat.test-while-idle=true
    spring.datasource.tomcat.test-on-borrow=true 
    spring.datasource.tomcat.validation-query=SELECT 1
    
  • 属性说明

connection.png

相关文章

网友评论

      本文标题:数据库连接池检查 - Springboot项目

      本文链接:https://www.haomeiwen.com/subject/zedeyqtx.html