[Java] Set auto reconnect in Spring data JPA

To ensure service availability, Most application nee to restart service to resume. However, auto reconnect is a must requirement to ensure it can self-heal. For Spring data JPA, it can be done without alter code.In application.properties, add line below and restart service to apply settings.

## Check connection even in idle.
spring.datasource.testWhileIdle = true
## Healthcheck every 2 minutes.
spring.datasource.timeBetweenEvictionRunsMillis = 120000
## SQL statement to ensure it is healthy, it can change to get data if needed.
spring.datasource.validationQuery = SELECT 1

 

About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.