-2

Difference between @ConditionalOnClass, @ConditionalOnMissingClass?

Can someone give me the difference between these annotations?

3 Answers3

1

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

Takrem
  • 41
  • 6
0

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.

Vasily Liaskovsky
  • 2,248
  • 1
  • 17
  • 32
0

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.

Ravindra
  • 289
  • 1
  • 4
  • 10