1 year ago

#388216

test-img

MFEB

Spring Boot Listener for database connection failures

Is there a listener or interceptor that I can use to be notified when my application looses connection to my database? If I turn off the database as my application is running I get a log statement for it.

"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@3cb8289f (This connection has been closed.). 

Ive tried to use the ConnectionEventListener but that didn't seem to work.


@Slf4j
@Service
public class JDBCConnectionListener implements ConnectionEventListener {
    @Override
    public void connectionClosed(ConnectionEvent event) {
        log.error("connection closed");
    }

    @Override
    public void connectionErrorOccurred(ConnectionEvent event) {
        log.error("connection error");
    }
}

Im using SpringBoot, JPA/Hibernate, and liquibase. My repositories extend CrudRepository.

java

spring-boot

jdbc

0 Answers

Your Answer

Accepted video resources