I have a spring boot application that connects to a MySql database. I have two jobs which are running every day, at 12am and 6am. Both take data from mysql db.
The problem is that, almost every day, while running spring jobs I lose connection with the database with the following error:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 65,098,262 milliseconds ago. The last packet sent successfully to the server was 65,098,264 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.
What i've tried so far:
I added in application.properties:
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=Select 1
In 'spring.datasource.url' I added autoReconnect=true and/or autoReconnectForPools=true
But no good result ..
Could you please help me with an idee to avoid this? Thank you.