JDBC : No operations allowed after connection closed;DataSourceUtils HikariPool;

报错信息:

信息1: com.mysql.cj.exceptions.ConnectionIsClosedException: No operations allowed after connection closed.

信息2: No operations allowed after connection closed。

信息3: JdbcTemplate DataSourceUtils HikariPool

springboot 项目 使用 JdbcTemplate 每天中文12点定时任务开启,存储数据的业务;第一次部署连接正常存储后,到第二天中午,代码就报错了,说明连接已经断开了。。。

Mysql 服务器默认的“wait_timeout”是8小时 在检测到8小时不用,人家会自动断开;自己代码这边还去请求数据库,那么就会报错连接已经断开,导致业务不能继续。

目前感觉应该在yml配置如下:

initialSize: 5
minIdle: 10
maxActive: 1000
#配置获取连接等待超时的时间
maxWait: 60000
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
#配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1
#指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除.
testWhileIdle: true
#指明是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个
testOnBorrow: true
#指明是否在归还到池中前进行检验
testOnReturn: false
#连接池配置
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
spring.datasource.validation-query=SELECT 1
spring.datasource.test-on-borrow=false
spring.datasource.test-while-idle=true
spring.datasource.time-between-eviction-runs-millis=18800

 

有可能会解决这问题,还没进行测试验证。

posted @ 2022-09-16 14:09  Birdgeduan  阅读(416)  评论(0编辑  收藏  举报