java - 空闲 AWS 实例上的 Web 服务中出现 CommunicationsException

标签 java mysql spring web-services

我有两个网络服务。一个 Web 服务调用另一个 Web 服务。这些 Web 服务托管在两个不同的 AWS 实例上。如果被调用的 Web 服务空闲一段时间,我会收到此异常 -

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

如果我重新启动 AWS 实例,就不会出现此异常。

使用Tomcat作为服务器,Mysql作为数据库,使用spring-mvc开发的webservices。

我在互联网上搜索,但发现不推荐'autoReconnect=true'。 并且不确定我可以增加多少“wait_timeout”,因为我不确定有多少时间实例将空闲。

请建议可以做什么。

最佳答案

在本例中,使用 IP 地址连接数据库时出现问题,而不是在数据库连接字符串中使用服务器的域名,问题得到解决。

关于java - 空闲 AWS 实例上的 Web 服务中出现 CommunicationsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23928030/

相关文章:

Java,如何解析 JSON 进行地理定位?

使用 ObjectMapper 将 POJO 转换为 HashMap<String,String> 时出现 java.lang.String out of START_ARRAY 错误

php - 在 2 层服务器中使用 mysql_real_escape_string 的 zend 框架

java - eclipse 无法识别错误更正

sql - 在一个查询中订购混合混合 mysql 搜索结果?

MySQL插入无效日期

java - 无法更改 HTTP 接受 header - 使用不同的语言环境解析策略

java - 选择要在 RESTful Web 服务中发布的属性

java - 为什么 Spring Boot MVC 总是从我的表单返回 null 值?

java - 使用 Maven 时,<fork>true</fork> 在 pom.xml 中意味着什么?