如何克服org.springframework.dao.RecoverableDataAccessException?

时间:2017-04-21 14:35:37

标签: java mysql spring tomcat exception

将Spring项目连接到MySQL服务器时,我一直收到连接问题。我尝试过在网上找到的各种技巧,但无济于事。为了摆脱这种困境,我需要帮助。我将下面的Spring设置和堆栈跟踪放在一起。

弹簧设置

spring.datasource.tomcat.initialize=true
spring.dataSource.tomcat.url=jdbc:mysql://nope/canttellyou?
autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
spring.dataSource.tomcat.username=nope
spring.dataSource.tomcat.password=sorry
spring.dataSource.tomcat.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=SELECT 1 
spring.datasource.tomcat.log-validation-errors=true

栈跟踪

stackTrace: org.springframework.dao.RecoverableDataAccessException: 
PreparedStatementCallback; SQL [select catname from animals]; The last 
packet successfully received from the server was 52,962,310 
milliseconds ago.  The last packet sent successfully to the server was 
52,962,310 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.; nested 
exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
The last packet successfully received from the server was 52,962,310 
milliseconds ago.  The last packet sent successfully to the server was 
52,962,310 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.

1 个答案:

答案 0 :(得分:0)

我一直有同样的问题。我认为我们要打开的配置设置是:

testWhileIdle

这是相关的tomcat connection pool docs

直到明天我才知道这是否适合我。