如果我的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.
为了解决这个问题,我读到 MySQL 具有一个wait_timeout默认设置为8小时(28800秒)的名称参数,此后所有非活动连接都关闭了,因此我的Spring Boot应用程序停止工作…
wait_timeout
我的问题是:
我解决了如下所述的问题:http : //blog.netgloo.com/2015/07/09/spring-boot-communications-link-failure-with- mysql-and-hibernate/,并在application.properties文件中添加了以下配置:
application.properties
spring.datasource.tomcat.testWhileIdle = true spring.datasource.tomcat.timeBetweenEvictionRunsMillis = 60000 spring.datasource.tomcat.validationQuery = SELECT 1