【问题标题】:How to overcome org.springframework.dao.RecoverableDataAccessException?如何克服 org.springframework.dao.RecoverableDataAccessException?
【发布时间】:2023-03-24 09:12:01
【问题描述】:

在将我的 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.

【问题讨论】:

    标签: java mysql spring tomcat exception


    【解决方案1】:

    我也遇到了同样的问题。我想我们要开启的配置设置是:

    testWhileIdle
    

    这是相关的tomcat connection pool docs

    直到明天我才会知道这是否对我有用。

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      • 2013-12-17
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      • 2016-01-10
      • 2023-03-31
      相关资源
      最近更新 更多