And*_*rea 10 mysql spring hibernate jdbc spring-boot
如果我的Spring Boot应用程序在几个小时内处于非活动状态(例如在夜间),我会收到此错误:
2015-05-19 09:16:32.666 WARN 20582 --- [http-nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 08S01
2015-05-19 09:16:32.668 ERROR 20582 --- [http-nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : Communications link failure
The last packet successfully received from the server was 29.792.613 milliseconds ago. The last packet sent successfully to the server was 6 milliseconds ago.
Run Code Online (Sandbox Code Playgroud)
试图解决这个问题我读到MySQL有一个名为wait_timeoutsetted 的参数,默认为8小时(28800秒),在此之后我的所有非活动连接都关闭了,所以我的Spring Boot应用程序停止工作......
我的问题是:
编辑
这里还有其他类似/有用的问题:
从上面的参考文献中我可以得出结论,一种解决方案是添加C3p0作为附加库并正确配置它以避免通信链接错误.
这是我唯一的解决方案吗?是不是有更多"集成"Spring/Spring Boot的解决方案(即没有添加外部库)?
And*_*rea 16
我解决了这里描述的问题:http:
//blog.netgloo.com/2015/07/09/spring-boot-communications-link-failure-with-mysql-and-hibernate/,在application.properties文件中添加以下配置:
spring.datasource.tomcat.testWhileIdle = true
spring.datasource.tomcat.timeBetweenEvictionRunsMillis = 60000
spring.datasource.tomcat.validationQuery = SELECT 1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10525 次 |
| 最近记录: |