Closed
Description
Using the new @ServiceConnection
does not work as I would expect when applied within an interface
. It starts the container on a random port rather than my spring defined port.
@DynamicPropertySource
does work as I expect.
public interface PostgresContainer {
@Container
// @ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>("postgres:11.1");
@DynamicPropertySource
static void initialize(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgreSQLContainer::getJdbcUrl);
registry.add("spring.datasource.username", postgreSQLContainer::getUsername);
registry.add("spring.datasource.password", postgreSQLContainer::getPassword);
}
}