Skip to content

Containers are not started when using @ImportTestcontainers #38913

@philwebb

Description

@philwebb

From @sleepo581 in #38831 (comment)

After migrating to spring-boot v3.2.1 tests with @ImportTestcontainers are failing because container is not started.
E.g.:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'spring.datasource.url' to java.lang.String:

    Reason: java.lang.IllegalStateException: Mapped port can only be obtained after the container is started`
public interface Containers {

    @Container
    PostgreSQLContainer<?> postgresContainer = new PostgreSQLContainer<>("postgres:16.1");

    @DynamicPropertySource
    static void setConnectionProperties(DynamicPropertyRegistry registry) {
        registry.add("spring.datasource.url", postgresContainer::getJdbcUrl);
        registry.add("spring.datasource.password", postgresContainer::getPassword);
        registry.add("spring.datasource.username", postgresContainer::getUsername);
    }
 }

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions