Skip to content

ApplicationContextRunner does not work correctly when AutoConfiguration class has not @Configuration #13129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
filiphr opened this issue May 9, 2018 · 3 comments
Assignees
Labels
for: external-project For an external project and not something we can fix

Comments

@filiphr
Copy link
Contributor

filiphr commented May 9, 2018

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 9, 2018
@wilkinsona
Copy link
Member

Thanks for the sample.

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.

@wilkinsona wilkinsona added type: bug A general bug for: team-attention An issue we'd like other members of the team to review and removed status: waiting-for-triage An issue we've not yet triaged labels May 10, 2018
@wilkinsona wilkinsona added this to the 2.0.x milestone May 10, 2018
@filiphr
Copy link
Contributor Author

filiphr commented May 10, 2018

Thanks a lot analysis and looking into it

@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label May 16, 2018
@wilkinsona wilkinsona self-assigned this May 16, 2018
@wilkinsona
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

4 participants