新聞中心
使用jdbc連接MySQL,如果連接失效,可能會報(bào)類似的錯(cuò)誤:
在五原等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)整合營銷推廣,外貿(mào)網(wǎng)站制作,五原網(wǎng)站建設(shè)費(fèi)用合理。
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.
如錯(cuò)誤提示,可以在連接的url上添加autoReconnect=true來解決。
需要注意的是:mysql是不推薦使用autoReconnect配置,因?yàn)槿绻麤]有合適處理SQLException的話,它會帶來一些數(shù)據(jù)一致性的副作用,可以參考:https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html中的autoReconect部分。
spring boot 1.4+需要看使用的是什么數(shù)據(jù)庫連接池庫,支持的連接池包括:tomcat, hikari, dbcp(1.5+廢棄), dbcp2。
tomcat
spring.datasource.tomcat.test-on-borrow=true spring.datasource.tomcat.validation-query=SELECT 1
dbcp2
spring.datasource.dbcp2.test-on-borrow=true spring.datasource.dbcp2.validation-query=SELECT 1
總結(jié)
以上所述是小編給大家介紹的Spring Boot 配置MySQL數(shù)據(jù)庫重連的操作方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!
當(dāng)前名稱:SpringBoot配置MySQL數(shù)據(jù)庫重連的操作方法
網(wǎng)頁URL:http://fisionsoft.com.cn/article/ihisdh.html