1

i'm using spring-boot and datasource with jdbc template (postgres). in my service i do

@Autowired
public MyDao(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
}

and later jdbcTemplate().query(...);. all works as expected but when i restart db, it stops working. looks like datasource doesn't reconnect. i got:

org.postgresql.util.PSQLException: This connection has been closed.

i got same error when i add:

spring:
  datasource:
    testOnBorrow: true
    validationQuery: select 1

how to make datasource reconnect automatically?

1

1 Answer 1

3

actually i found it does reconnect after adding:

spring:
  datasource:
    testOnBorrow: true
    validationQuery: select 1

i just needed to wait the default validationInterval that is 30sec

Sign up to request clarification or add additional context in comments.

1 Comment

Can you accept your answer so that the question does not show as unanswered? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.