网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

SpringBoot配置MySQL数据库重连的操作方法-创新互联

使用jdbc连接MySQL,如果连接失效,可能会报类似的错误:

成都创新互联公司作为成都网站建设公司,专注网站建设、网站设计,有关成都企业网站定制方案、改版、费用等问题,行业涉及成都混凝土搅拌罐车等多个领域,已为上千家企业服务,得到了客户的尊重与认可。

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 84,371,623 milliseconds ago.

The last packet sent successfully to the server was 78,860,631 milliseconds ago. is longer than the server configured value of 'wait_timeout'.

You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

如错误提示,可以在连接的url上添加autoReconnect=true来解决。

需要注意的是:mysql是不推荐使用autoReconnect配置,因为如果没有合适处理SQLException的话,它会带来一些数据一致性的副作用,可以参考:https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html中的autoReconect部分。

spring boot 1.4+需要看使用的是什么数据库连接池库,支持的连接池包括:tomcat, hikari, dbcp(1.5+废弃), dbcp2。

tomcat

spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=SELECT 1


当前题目:SpringBoot配置MySQL数据库重连的操作方法-创新互联
文章链接:http://bjjierui.cn/article/eeeph.html

其他资讯