Skip to content
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

[ISSUE] ConditionalOnBean should only be used on auto-configuration classes #15906

Open
bclozel opened this issue Feb 17, 2024 · 1 comment
Open
Labels
on-jira triaged Issues reviewed by a dev and considered valid. Will be added in Jira.

Comments

@bclozel
Copy link

bclozel commented Feb 17, 2024

Article and Module Links

https://www.baeldung.com/spring-conditional-annotations#predefined-conditional-annotations
https://github.com/eugenp/tutorials/tree/master/spring-boot-modules/spring-boot-annotations-2

Describe the Issue

The article promotes the use of @ConditionalOnBean on actual components or bean declaration in user configuration.

This is explicitly called out as an invalid case in the Spring Boot Javadoc:

The condition can only match the bean definitions that have been processed by the application context so far and, as such, it is strongly recommended to use this condition on auto-configuration classes only. If a candidate bean may be created by another auto-configuration, make sure that the one using this condition runs after.

Please remove this case from samples and articles.

@apeterlic apeterlic added the triaged Issues reviewed by a dev and considered valid. Will be added in Jira. label Feb 28, 2024
@apeterlic
Copy link
Collaborator

Hey @bclozel,

Thanks for the heads up. We'll update the article to fix this.

Regards,
Team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on-jira triaged Issues reviewed by a dev and considered valid. Will be added in Jira.
Projects
None yet
Development

No branches or pull requests

3 participants