Spring Boot @ConditionalOnBean Annotation Example
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhK7wyjGW--xEoroO0IVgkUiLHNLSwtd8tDVBrPyJ1P-h_Ry142vLo-D4JyQuCaa3DYu77Br7685P5wDLvGX2dfbbXI8DQgmIoRCUnbPOUjZZizagaCrYaRIlTe1kEJPalY7mcMl8jJmTL985TOzQlHMC7U1Abx15eLiCCXjXk83UtO9z4sd_L6nPG6fA/w400-h184/conditionalonbean.png)
In this section we will learn about @ConditionalOnBean Annotation. The @ConditionalOnBean annotation let a bean be loaded based on the presence of specific bean inside Spring container. The @ConditionalOnBean annotation may be used on any class annotated with @Component , @Service & @Repository or on methods annotated with @Bean . 1. Using @ConditionalOnBean on @Bean method For example, @ConditionalOnBean (name = "emailNotificationProvider" ) , when the Bean of name "emailNotificationProvider" exists in the container, the bean emailNotification will be loaded. @Bean ( "emailNotification" ) @ConditionalOnBean (name = "emailNotificationProvider" ) public EmailNotificationService emailNotificationService () { return new EmailNotificationService(); } 2. Using @ConditionalOnBean on @Service class For example, @ConditionalOnBean (name = "smsNotificationProvider" ) , when the Bean of name "smsNotificationProvi