Skip to content

@ServiceConnection is not found when used in an interface implemented by a test class #37671

Closed
@therealaleko

Description

@therealaleko

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);
  }
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions