'Spring boot autoconfiguration @ConditionalOnBean behaving weirdly
I am writing a spring boot library that creates an autoconfiguration class conditionally if a specific bean is present. The weird thing that is happening is in Conditions Evaluation Report, I see two entries for the same bean, highlighted below. Has someone else also faced similar issue ? How can I resolve this ? I tried reordering the library that was causing this.
============================
CONDITIONS EVALUATION REPORT
============================
Positive matches:
-----------------
MyTestConfguration:
Did not match:
- @ConditionalOnBean (types: com.onkaar.test.Security SearchStrategy: all) did not find any beans of type com.onkaar.test.Security (OnBeanCondition)
Matched:
- @ConditionalOnProperty (com.onkaar.xyz-property) matched (OnPropertyCondition)
- @ConditionalOnBean (types: com.onkaar.test.Security; SearchStrategy: all) found bean 'testSecurity' (OnBeanCondition)
My concern is that if the same bean is showing in "Matched"; then why is it also showing up in "Did not match" section and due to which this autoconfiguration class not getting created.
Thanks for your help
Solution 1:[1]
Okay, so we were using annotation @ComponentScan in the configuration class which was causing this issue. After removing this annotation, the issue is resolved.
Am still curious to understand how @ComponentScan can cause this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Onkaar Singh |
