[英]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.