Springboot:Springboot+mysql5.7搭建服務,超過8小時連接mysql失敗


報錯信息

2017-03-12 03:00:02.539 ERROR 9311 --- [nio-9000-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;
 nested exception is org.springframework.dao.RecoverableDataAccessException: StatementCallback; SQL [DELETE FROM search_product]; 
  The last packet sent successfully to the server was 86,395,487 milliseconds ago. 
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.] with root cause

 

經查發現原來是mysql默認會將8個小時內沒有操作過的數據庫連接斷開。
項目是springboot。
找到一個解決辦法,在application.properties中設置datasource的時候,加入如下設置:
(testWhileIdle,validationQuery,timeBetweenEvictionRunsMillis)

#設置每隔一小時向mysql進行一次連接可用確認
srping.dataSource.bySearch.testWhileIdle = true
spring.dataSource.bySearch.validationQuery=SELECT 1
spring.dataSource.bySearch.timeBetweenEvictionRunsMillis = 3600000

 

文章轉載至:https://blog.csdn.net/u012859681/article/details/62051509?utm_source=blogxgwz5


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM