You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is most definitely my error that I forgot to add an @Configuration to my custom auto configuration.
The problem occurs when an auto configuration class (e.g. MyCustomAutoConfiguration) has a nested configuration class with @EnableConfigurationProperties is missing a @Configuration (the root class) then the Spring Boot application works correctly. However, when using the ApplicationContextRunner the behaviour is not the same.
See this repository for a reproducing example. In the example repo if you move the @EnableConfigurationProperties then tests that were failing before will pass.
If you think that there is nothing that Boot can do about this, feel free to close it. I was just confused why it was working in one instance, but not in the other
The text was updated successfully, but these errors were encountered:
The difference in behaviour is due to a difference in how MyCustomAutoConfiguration is registered with the application context. When you use @SpringBootTest it's registered via the import selector for auto-configuration and is processed as a configuration class. When you use ApplicationContextRunner it's registered via a call to org.springframework.context.annotation.AnnotationConfigRegistry.register(Class<?>...) and isn't processed in the same way. Critically, it isn't processed by ConfigurationClassParser and doesn't go through its processMemberClasses method. It's there that the nested configuration class is found when using @SpringBootTest.
I believe this is a Spring Framework bug so I have opened SPR-16839. If the Framework team disagree we can re-open this issue and look for a workaround.
This is most definitely my error that I forgot to add an
@Configuration
to my custom auto configuration.The problem occurs when an auto configuration class (e.g.
MyCustomAutoConfiguration
) has a nested configuration class with@EnableConfigurationProperties
is missing a@Configuration
(the root class) then the Spring Boot application works correctly. However, when using theApplicationContextRunner
the behaviour is not the same.See this repository for a reproducing example. In the example repo if you move the
@EnableConfigurationProperties
then tests that were failing before will pass.If you think that there is nothing that Boot can do about this, feel free to close it. I was just confused why it was working in one instance, but not in the other
The text was updated successfully, but these errors were encountered: