I assume the download configures the DataSource for you. In this case, and since you are using MySQL, you can add the following to application.properties to 1.3
spring.datasource.testOnBorrow=true spring.datasource.validationQuery=SELECT 1
As djxak notes in a comment, 1.4+ defines specific namespaces for the four Spring connection pools. Boot support: tomcat , hikari , dbcp , dbcp2 ( dbcp deprecated from 1.5). You need to check which connection pool you are using and check if this feature is supported. The example above was for tomcat, so you need to write it to 1.4 +:
spring.datasource.tomcat.testOnBorrow=true spring.datasource.tomcat.validationQuery=SELECT 1
Please note that using autoReconnect not recommended :
Using this function is not recommended because it has side effects related to session state and data consistency when applications do not handle SQLExceptions correctly and are for use only when you cannot configure the application to handle SQLExceptions caused by dead and stale connections.
Stephane Nicoll Mar 27 '14 at 12:18 2014-03-27 12:18
source share