-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
In Spring Boot until 3.3.x I was able to inject an instance of DynamicPropertyRegistry
into a @Bean
configuration in my Test classes like this:
@TestConfiguration
public class DemoTestConfig {
@Bean
DummyService dummyService(DynamicPropertyRegistry registry) {
registry.add("demo.test.prop", () -> "Hello World");
return new DummyService();
}
}
In Spring Boot 3.4.0-M1 this also does work, but only as long as I do not have spring-boot-testcontainers
in classpath/pom.xml. With Testcontainers in classpath, Spring Boots complains that two instances of DynamicPropertyRegistry are found:
Parameter 0 of method dummyService in com.example.demo.DemoTestConfig required a single bean, but 2 were found:
- dynamicPropertyRegistry: defined by method 'dynamicPropertyRegistry' in class path resource [org/springframework/boot/testcontainers/properties/TestcontainersPropertySourceAutoConfiguration.class]
- org.springframework.test.context.support.DynamicPropertiesContextCustomizer.dynamicPropertyRegistry: a programmatically registered singleton
In 3.3.x it works with and without spring-boot-testcontainers
in pom.xml.
I created an example project that shows the behaviour with Spring Boot 3.3.2 and 3.4.0-M1 here: https://github.com/nilshartmann/spring-boot-3-4-dynamic_properties. See README.md
there how to run the test in 3.3.2 and the failing one in 3.4.0 using Maven.
In Spring 6.2.0-M1 I saw this addition recently spring-projects/spring-framework#32271, maybe that is related?