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
Leave a Reply