Using spring-boot-starter-parent:3.3.12.
I'm calling mvn verify
. One of the springboot tests looks a bit like this...
@SpringBootTest
@ActiveProfiles("test")
public class ControllerIntegrationTests {
In my application.properties
I have
notifications:
url: http://uat.internal:8080
And in application-test.properties
I have
notifications:
url: http://localhost:8080
In one of my configurations I have added a System.out
@Bean
public NotificationClient notificationClient(@Value("${notifications.url}") String baseUrl, @Value("${windows.username}") String username,
@Value("${windows.password}") String password) {
String[] profiles = environment.getActiveProfiles();
System.out.println("*** profiles: " + Joiner.on(",").join(profiles));
System.out.println("*** notifications.url: " + environment.getProperty("notifications.url"));
return new NotificationClient(baseUrl, username, password);
}
Which produces this in the logs...
2025-07-22T10:33:41.368+01:00 INFO 32896 --- [ main] [ ] u.c.f.primary.ControllerIntegrationTests : Starting ControllerIntegrationTests using Java 17.0.15 with PID 32896
2025-07-22T10:33:41.372+01:00 INFO 32896 --- [ main] [ ] u.c.f.primary.ControllerIntegrationTests : The following 1 profile is active: "test"
2025-07-22T10:33:42.676+01:00 INFO 32896 --- [ main] [ ] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2025-07-22T10:33:42.808+01:00 INFO 32896 --- [ main] [ ] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 120 ms. Found 1 JPA repository interface.
2025-07-22T10:33:43.346+01:00 WARN 32896 --- [ main] [ ] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor [io.awspring.cloud.messaging.internalSqsListenerAnnotationBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE.
2025-07-22T10:33:43.920+01:00 WARN 32896 --- [ main] [ ] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2025-07-22T10:33:43.952+01:00 INFO 32896 --- [ main] [ ] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2025-07-22T10:33:43.953+01:00 INFO 32896 --- [ main] [ ] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2525 ms
2025-07-22T10:33:44.782+01:00 WARN 32896 --- [ main] [ ] o.s.aop.framework.CglibAopProxy : Unable to proxy interface-implementing method [public final java.lang.Object org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice.beforeBodyWrite(java.lang.Object,org.springframework.core.MethodParameter,org.springframework.http.MediaType,java.lang.Class,org.springframework.http.server.ServerHttpRequest,org.springframework.http.server.ServerHttpResponse)] because it is marked as final, consider using interface-based JDK proxies instead.
2025-07-22T10:33:44.786+01:00 WARN 32896 --- [ main] [ ] o.s.aop.framework.CglibAopProxy : Unable to proxy interface-implementing method [public final java.lang.Object org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice.beforeBodyWrite(java.lang.Object,org.springframework.core.MethodParameter,org.springframework.http.MediaType,java.lang.Class,org.springframework.http.server.ServerHttpRequest,org.springframework.http.server.ServerHttpResponse)] because it is marked as final, consider using interface-based JDK proxies instead.
*** profiles: test
*** notifications.url: http://uat.internal:8080
And to top it off, this only occurs for the first test. Subsequent tests all output the correct [test] property. ie.
*** profiles: test
*** notifications.url: http://localhost:1081
Why is the first test using the default property despite claiming the test profile is active?
Seems the spring-boot-maven-plugin plugin might be the culprit, which I'd added to get the openapi plugin working. Removing that seems to have fixed the issue.
Turns out after some investigation that the spring-boot-maven-plugin
plugin was creating a bean using the default properties, confirmed by logging them when the instance was used. The plugin was executing goals start/stop so this "bad" bean was hanging around during integration tests. It appears the integration tests were using said "bad" bean and not the one that was supposed to be injected.
By moving spring-boot-maven-plugin
to the bottom of the POM and changing the start
goal phase from pre-integration-test
to integration-test
has solved the issue as the "bad" bean is created after the tests have finished.