Springboot:Springboot+mysql5.7搭建服务,超过8小时连接mysql失败

Posted 怒吼的萝卜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Springboot:Springboot+mysql5.7搭建服务,超过8小时连接mysql失败相关的知识,希望对你有一定的参考价值。

报错信息

2017-03-12 03:00:02.539 ERROR 9311 --- [nio-9000-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;
 nested exception is org.springframework.dao.RecoverableDataAccessException: StatementCallback; SQL [DELETE FROM search_product]; 
  The last packet sent successfully to the server was 86,395,487 milliseconds ago. 
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.] with root cause

 

经查发现原来是mysql默认会将8个小时内没有操作过的数据库连接断开。
项目是springboot。
找到一个解决办法,在application.properties中设置datasource的时候,加入如下设置:
(testWhileIdle,validationQuery,timeBetweenEvictionRunsMillis)

#设置每隔一小时向mysql进行一次连接可用确认
srping.dataSource.bySearch.testWhileIdle = true
spring.dataSource.bySearch.validationQuery=SELECT 1
spring.dataSource.bySearch.timeBetweenEvictionRunsMillis = 3600000

 

文章转载至:https://blog.csdn.net/u012859681/article/details/62051509?utm_source=blogxgwz5

以上是关于Springboot:Springboot+mysql5.7搭建服务,超过8小时连接mysql失败的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot-06:SpringBoot增删改查一套完整的考试案例

SpringBoot整合Jsp和Thymeleaf (附工程)

SpringBoot2 java???????????? Configuration???PropertySource????????????????????????

SpringBoot-Mysql模板多数据源加载

基于springboot框架的小程序共享车位管理系统

记一次Springboot集成druid系统间歇性报communications link failure