[ISSUE] ConditionalOnBean should only be used on auto-configuration classes
bclozel opened this issue · comments
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.