Showing posts with the label @ConditionalOnMissingBean

Spring Boot @ConditionalOnMissingBean Annotation Example

In this section we will learn about @ ConditionalOnMissingBean   Annotation. You can use  @ ConditionalOnMissingBean  if you want to load a bean only if another bean doesn’t exist in the application context. @Bean @ConditionalOnMissingBean public NotificationService emailNotificationService () { return new EmailNotificationService(); } This example loads the EmailNotificationService into the application context if there is no other NotificationService exist in application context.  The following example creates a Spring Boot web application which uses  @ConditionalOnMissingBean annotation .  Project Directory pom.xml <? xml version ="1.0" encoding ="UTF-8" ?> < project xmlns ="" xmlns: xsi ="" xsi :schemaLocation ="" > < modelVersion >4.0.0</ mode