在写项目时候发现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
- Communications milliseconds successfully received failurecommunications milliseconds successfully received milliseconds successfully received原因 milliseconds successfully packet server communications failure mysql link 参数exit exit_failure exit_success milliseconds communications communicationsexception communications exceptions mysql communicationsexception jdbc communications cjcommunicationsexception communications exceptions