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 ="http://maven.apache.org/POM/4.0.0" xmlns: xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi :schemaLocation ="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion >4.0.0</ mode...