[英]Connection to Db dies after >4<24 in spring-boot jpa hibernate
[英]spring-boot:jdbc re-connection after db outage
我正在使用带有jdbc模板的spring-boot和datasource(postgres)。 在我的服务中我做
@Autowired
public MyDao(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
以后jdbcTemplate().query(...);
。 一切都按预期工作,但当我重新启动数据库时,它停止工作。 看起来像数据源不重新连接。 我有:
org.postgresql.util.PSQLException: This connection has been closed.
我添加时出现同样的错误:
spring:
datasource:
testOnBorrow: true
validationQuery: select 1
如何自动重新连接数据源?
实际上我发现它添加后重新连接:
spring:
datasource:
testOnBorrow: true
validationQuery: select 1
我只需要等待30秒的默认validationInterval
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.