@ConditionalOnMissingBean does not work if the "missing bean" is a Spring Data Repository. Attached you find an demo.zip application demonstrating this issue.

The log is also misleading:

DefaultDemoRepository matched: - @ConditionalOnMissingBean (types: com.example.demo.SpecialDemoRepository,com.example.demo.DemoRepository; SearchStrategy: all) did not find any beans (OnBeanCondition)

SpecialDemoRepository matched: - @ConditionalOnProperty (spring.datasource.driver-class-name=org.h2.Driver) matched (OnPropertyCondition)

Working with @DependsOn or other annotations to affect the autoconfiguration order do not help.

Something similar has been already asked on StackOverflow. Sadly without answer - thus leading to the conclusion that this might be a bug.

Comment From: snicoll

Thanks for the sample. @ConditionalOnMissingBean has a specific note in the 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.

The conditions on DefaultDemoRepository can only provide the expected result if the targets have already processed. They are being processed and it's no surprise it does not work.