jdbc 模板是否在不活动时关闭连接
Does jdbc template closes connections in case of inactivity
在我的 Spring 引导微服务中,我自动配置了 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
但是在超过 20 小时的不活动之后,我发现 connection is closed
并且我的 Web 服务被阻止了。
Spring Boot 是否会在一段时间后自动关闭所有不活动的连接?
编辑 3 月 21 日
如果我没有每隔 X 分钟或在从池中取出它之前添加连接测试,这是否意味着 jdbcTemplate 不会在长时间不活动的情况下重新创建它们?
spring.datasource.tomcat.testWhileIdle = true
spring.datasource.tomcat.timeBetweenEvictionRunsMillis = 50000
spring.datasource.tomcat.validationQuery = SELECT 1
将这些值添加到 application.properties
文件
在我的 Spring 引导微服务中,我自动配置了 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
但是在超过 20 小时的不活动之后,我发现 connection is closed
并且我的 Web 服务被阻止了。
Spring Boot 是否会在一段时间后自动关闭所有不活动的连接?
编辑 3 月 21 日 如果我没有每隔 X 分钟或在从池中取出它之前添加连接测试,这是否意味着 jdbcTemplate 不会在长时间不活动的情况下重新创建它们?
spring.datasource.tomcat.testWhileIdle = true
spring.datasource.tomcat.timeBetweenEvictionRunsMillis = 50000
spring.datasource.tomcat.validationQuery = SELECT 1
将这些值添加到 application.properties
文件