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
{{ message }}
Repository navigation
ApplicationContextRunner does not work correctly when AutoConfiguration class has not @Configuration #13129
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 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.
Activity
wilkinsona commentedon May 10, 2018
Thanks for the sample.
The difference in behaviour is due to a difference in how
MyCustomAutoConfigurationis registered with the application context. When you use@SpringBootTestit's registered via the import selector for auto-configuration and is processed as a configuration class. When you useApplicationContextRunnerit's registered via a call toorg.springframework.context.annotation.AnnotationConfigRegistry.register(Class<?>...)and isn't processed in the same way. Critically, it isn't processed byConfigurationClassParserand doesn't go through itsprocessMemberClassesmethod. It's there that the nested configuration class is found when using@SpringBootTest.filiphr commentedon May 10, 2018
Thanks a lot analysis and looking into it
wilkinsona commentedon May 18, 2018
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.