加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何克服org.springframework.dao.RecoverableDataAcces

发布时间:2020-12-15 02:19:08 所属栏目:Java 来源:网络整理
导读:将 Spring项目连接到 MySQL服务器时,我一直收到连接问题.我尝试过在网上找到的各种技巧,但无济于事.为了摆脱这种困境,我需要帮助.我正在下面放置我的Spring设置和堆栈跟踪. 弹簧设置 spring.datasource.tomcat.initialize=truespring.dataSource.tomcat.url=
将 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,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,or using the Connector/J 
connection property 'autoReconnect=true' to avoid this problem.

解决方法

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

testWhileIdle

这是相关的tomcat connection pool docs

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读