Hello. I have a very basic setup for running Sprin...
# spring
k
Hello. I have a very basic setup for running Springboot tests using a postgresql test container. The first test runs fine, however subsequent tests all fail and yell the following at me:
Copy code
2025-06-21T10:42:16.910+02:00  WARN 74817 --- [app] [    Test worker] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@5a0c0680 (This connection has been closed.). Possibly consider using a shorter maxLifetime value.
My base test class looks like this:
Copy code
@Testcontainers
abstract class SpringBootTestBase {

    companion object {

        @Container
        @JvmStatic
        val postgres = PostgreSQLContainer<Nothing>("postgres:15").apply {
            withDatabaseName("testdb")
            withUsername("test")
            withPassword("test")
        }

        @JvmStatic
        @DynamicPropertySource
        fun registerPgProperties(registry: DynamicPropertyRegistry) {
            registry.add("spring.datasource.url", postgres::getJdbcUrl)
            registry.add("spring.datasource.username", postgres::getUsername)
            registry.add("spring.datasource.password", postgres::getPassword)
        }
    }
}
I have overridden properties for hikari. I have no special test properties either. Any idea?
m
bit off topic: but if you want Postgres in your tests you may want to consider setting your datasource URL to testcontainers one - e.g.,
jdbc:tc:postgresql:15:///testdb
- see https://java.testcontainers.org/modules/databases/jdbc/ it will handle setup of Postgres for you
k
Thank you
k
This worked really well, Thank you @Marian Schubert