Reputation: 11071
In my Spring Boot microservice I have autoconfigured JdbcTemplate.
spring.datasource.url=jdbc:sqlserver://${DB_SERVER};PortNumber=${DB_PORT};failoverPartner=${DB_FAILOVER_SERVER};databaseName=${DB_NAME};
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASSWORD}
spring.datasource.driverClassName= com.microsoft.sqlserver.jdbc.SQLServerDriver
But after more that 20 hours of inactivity I see that connection is closed
and my web service is blocked.
Does Spring Boot closes all connection in case of inactivity automatically after some time?
EDIT 21 March If I don't add connection test every X minutes or before taking it from the pool does it mean that jdbcTemplate will not recreate them in cas of long inactivity?
Upvotes: 2
Views: 737
Reputation: 2575
spring.datasource.tomcat.testWhileIdle = true
spring.datasource.tomcat.timeBetweenEvictionRunsMillis = 50000
spring.datasource.tomcat.validationQuery = SELECT 1
Add these values to application.properties
file
Upvotes: 1