Skip to content

Commit b29c16e

Browse files
committed
Overcome MySQL's connection timeout after 8 hrs idle.
Fixed following exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 324,520,962 milliseconds ago. The last packet sent successfully to the server was 324,520,962 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. @see http://stackoverflow.com/questions/4950396/tomcat-configuration-using-dbcp
1 parent e3eb3e8 commit b29c16e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/main/java/ru/mystamps/web/config/DataSourceConfig.java

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public DataSource getDataSource() {
5151
dataSource.setUrl(env.getRequiredProperty("db.url"));
5252
dataSource.setUsername(env.getRequiredProperty("db.username"));
5353
dataSource.setPassword(env.getRequiredProperty("db.password"));
54+
dataSource.setValidationQuery("SELECT 1");
55+
dataSource.setTestOnBorrow(true);
5456

5557
return dataSource;
5658
}

0 commit comments

Comments
 (0)