Spring Boot JPA - 配置自动重新连接 [英] Spring Boot JPA - configuring auto reconnect

查看:1416
本文介绍了Spring Boot JPA - 配置自动重新连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很好的小春天开机jpa web应用程序。它部署在亚马逊豆茎上,并使用亚马逊rds来持久化数据。然而,它不经常使用,有一段时间后失败与这种异常:

I have a nice little spring boot jpa web application. It is deployed on amazon beanstalk and uses an amazon rds for persisting data. It is however not used that often and there for fails after a while with this kind of exception:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 79,870,633 milliseconds ago.  
The last packet sent successfully to the server was 79,870,634 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.

我不知道如何配置此设置,并且无法在 http://spring.io (一个非常好的网站)。

I am not sure how to configure this setting and can not find information on it on http://spring.io (a very good site though). Anybody have some ideas or pointers to information ?

推荐答案

我假设引导正在配置 DataSource 给你。在这种情况下,由于您使用MySQL,您可以将以下内容添加到您的 application.properties

spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1

请注意,使用 autoReconnect 不推荐


不建议使用此功能,因为当应用程序未正确处理SQLExcept时,它会产生与会话状态和数据一致性相关的副作用,并且仅当您无法将您的应用程序配置为正确处理由于死和连接失败而导致的SQLExcept时,才会使用它。

The use of this feature is not recommended, because it has side effects related to session state and data consistency when applications don't handle SQLExceptions properly, and is only designed to be used when you are unable to configure your application to handle SQLExceptions resulting from dead and stale connections properly.

这篇关于Spring Boot JPA - 配置自动重新连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆