」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 如何防止在春季啟動424小時後使用Hibernate的數據庫連接損失?

如何防止在春季啟動424小時後使用Hibernate的數據庫連接損失?

發佈於2025-03-22
瀏覽:244

How to Prevent Database Connection Loss After 424 Hours in Spring Boot with Hibernate? 
在彈簧啟動424小時後使用Hibernate

引起的:com.mysql.jdbc.exceptions.jdbc4.communicationsexpection:從服務器成功收到的最後一個數據包為56,006,037毫秒。 成功發送到服務器的最後一個數據包是56,006,037毫秒前。比服務器配置的“ 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.

To address this issue, it is recommended to configure appropriate connection properties in the application's configuration file (e.g., application.properties):

Remove idle connections if they have not been used within a specified time (spring.datasource.min-evictable-idle-time-millis).
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 56,006,037 milliseconds ago.  The last packet sent successfully to the server was 56,006,037 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.

By implementing these configurations, the connection pool will regularly test the validity of connections and replace those that have become stale, ensuring stable即使在延長了不活動的時間之後,數據庫連接。

版本聲明 本文轉載於:1729757864如有侵犯,請聯繫[email protected]刪除
最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3