异常信息:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link failure Last packet sent to the server was X ms ago

是由于MySQL的服务会在操作间隔8小时后断开,需要再次重连。断开之后的首次请求会抛出这个异常。

在使用spring jdbc连接时可使用以下方式解决该问题

spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=select 1
spring.datasource.maxAge=14400000
spring.datasource.default-auto-commit=true

感谢大家的阅读, 如有疑问可以加我微信