Home > front end >  Difference between @ConditionalOnClass , @ConditionalOnMissingClass
Difference between @ConditionalOnClass , @ConditionalOnMissingClass

Time:12-08

Difference between @ConditionalOnClass, @ConditionalOnMissingClass?

Can someone give me the difference between these annotations?

CodePudding user response:

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.

CodePudding user response:

With these annotations, spring will selectively skips the configuration based on the absence / presence of certain classes mentioned in the annotations.

This link (article) might help you to get more details on the same.

CodePudding user response:

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

  • Related