【发布时间】:2016-12-10 11:10:49
【问题描述】:
我正在使用带有 jdbc 模板 (postgres) 的 spring-boot 和数据源。在我的服务中,我愿意
@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
如何让数据源自动重连?
【问题讨论】:
-
见stackoverflow.com/questions/30451470/…(虽然是关于MySQL,但设置也适用于其他驱动程序)。
标签: java spring postgresql jdbc spring-boot