SpringBoot2 hikari关于 Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl处理

发布时间 2023-04-26 11:55:00作者: 海燕心海

项目启动不报错,如果静默15分钟没有数据库操作就报上述错误WARN 不影响程序运行

Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@16244d67 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.

发现SpringBoot2开始配置文件有所变化

spring:
  #数据库
  datasource:
    url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
    password: root
    username: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      max-lifetime: 30000 # 不能小于30秒,否则默认回到1800秒