我有一个很好的小Spring Boot JPA Web应用程序.它部署在Amazon Beanstalk上,并使用Amazon RDS来保存数据.然而,经常使用它并因此在一段时间后因此类异常而失败:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:从服务器成功收到的最后一个数据包是79,870,633毫秒.
成功发送到服务器的最后一个数据包是79,870,634毫秒.比服务器配置的'wait_timeout'值长.您应该考虑在应用程序中使用之前过期和/或测试连接有效性,增加服务器配置的客户端超时值,或使用Connector/J连接属性"autoReconnect = true"来避免此问题.
我不知道如何配置此设置,但无法在http://spring.io上找到相关信息(虽然这是一个非常好的网站).有哪些想法或信息指针?
我有一个使用spring-boot,jpa-hiberanate与mysql的应用程序.我收到此错误日志
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.
Run Code Online (Sandbox Code Playgroud)
这是我的application.properties
# DataSource settings: set here configurations for the database …Run Code Online (Sandbox Code Playgroud) 我正在运行Spring Boot连接到PostgreSQL数据库.我已经验证,如果在数据库之后启动Spring Boot,数据将写入数据库.
spring.datasource.url = jdbc:postgresql://localhost/dbname
spring.datasource.username = user
spring.datasource.password = secret
spring.datasource.driver-class-name = org.postgresql.Driver
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
Run Code Online (Sandbox Code Playgroud)
当开发中的数据库发生变化时,我会遇到异常:
PreparedStatementCallback; SQL []; This connection has been closed.; nested exception is org.postgresql.util.PSQLException: This connection has been closed.
请注意,异常发生时可以再次访问数据库; 我认为问题是连接是陈旧的,因为它最初连接的数据库端点由于重新启动而不再可用.重新启动Spring Boot可以解决此问题.
如何配置Spring Boot以重新连接到PostgreSQL,以便我不需要重新启动它?
我试图按照Spring Boot JPA中的答案- 配置自动重新连接和如何在spring jpa中关闭连接时如何重新连接数据库?.我不确定PostgreSQL的行为是否与MySQL不同.我阅读Spring Boot文档没有帮助; 我不知道所描述的组件是否足以理解我应该查看哪些文档.