引入druid查询数据库时间只要超过10秒会报错Communications link failure,The last packet successfully received from the server was xxx milliseconds ago(已解决)
在写项目时候发现springboot(springcloud)项目使用多数据源引入druid的时候,只要查询数据库时间超过10s就会报错:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet successfully received from the server was 10,023 milliseconds ago. The last packet sent successfully to the server was 10,027 milliseconds ago.
这两个错误困扰了我好久百度找到所有的解决方法都不能解决
原因:
我使用的dynamic-datasource-spring-boot-starter 版本为3.5.2版本过低
解决方法:
一、将dynamic-datasource-spring-boot-starter升级为3.6.1
二、该版本新增两个参数connectTimeout,和socketTimeout,在原有druid配置中新增这两个参数即可解决问题
druid:
connectTimeout: 60000
socketTimeout: 60000
本文来自博客园,作者:void_main(),转载请注明原文链接:https://www.cnblogs.com/void--main/p/17446486.html

浙公网安备 33010602011771号