”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 如何防止在春季启动424小时后使用Hibernate的数据库连接损失?

如何防止在春季启动424小时后使用Hibernate的数据库连接损失?

发布于2025-03-22
浏览:329

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