Difference between @ConditionalOnClass, @ConditionalOnMissingClass?
Can someone give me the difference between these annotations?
Difference between @ConditionalOnClass, @ConditionalOnMissingClass?
Can someone give me the difference between these annotations?
Spring @ConditionalOnClass
and @ConditionalOnMissingClass
annotations let @Configuration
classes be included based on the presence or absence of specific classes. So @ConditionalOnClass
loads a bean only if a certain class is on the classpath and @ConditionalOnMissingClass
loads a bean only if a certain class is not on the classpath.
More here
You can mark a bean class with any of the annotations, but they do opposite things. @ConditionalOnClass
includes bean of marked class if annotation's parameter is present on classpath. Whereas @ConditionalOnMissingClass
includes it if the class is absent.
These annotations are important part of autoconfiguration process when Spring chooses appropriate bean type based on application classpath.