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

有时会遇到一个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
    
  • 属性说明

数据库连接池检查 - Springboot项目_第1张图片
connection.png

你可能感兴趣的:(数据库连接池检查 - Springboot项目)