From 16e2a6a8957f60771ab5e0f161f6d23bb433ef26 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Wed, 6 Nov 2019 15:52:11 -0600 Subject: [PATCH] Prevent MySQL connection from getting killed After long periods of inactivity, the MySQL server will kill the connection [1]. The newly added configuration properties perform a validation query once per minute while idle to avoid the connection from being killed. [1] https://blog.netgloo.com/2015/07/09/spring-boot-communications-link-failure-with-mysql-and-hibernate/ --- src/main/resources/application.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e53683b..ab5bfef 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,3 +6,6 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.profiles.active=prod spring.session.store-type=jdbc spring.session.jdbc.initialize-schema=always +spring.datasource.testWhileIdle=true +spring.datasource.timeBetweenEvictionRunsMillis=60000 +spring.datasource.validationQuery=SELECT 1