Posts

Showing posts with the label @ConditionalOnMissingClass

Spring Boot @ConditionalOnMissingClass Annotation Example

Image
In this section we will learn about @ConditionalOnMissingClass  Annotation. The  @ConditionalOnMissingClass  can be used to register a bean only when the given class(es) cannot be found on the class-path.  For example, when providing library/framework classes to other developers, this annotation can be used to active certain beans only based on the absence of specific classes. The  @ConditionalOnMissingClass  annotation may be used on any class annotated with @Configuration ,  @Component ,  @Service  &  @Repository  or on methods annotated with  @Bean . 1. Using @ConditionalOnMissingClass on @Bean method To illustrate the use of  @ConditionalOnMissingClass , we will  create one simple service classe,  SMSNotificationService  class. public class SMSNotificationService { public SMSNotificationService() { System.out.println( "Inside SMSNotificationService Constructor" ); } public void se...