Spring Boot @ConditionalOnResource Annotation Example
In this section we will learn about @ConditionalOnResource Annotation. The @ConditionalOnResource annotation allows you to enable configuration only when a specific resource is available. We can specify resource's location of classpath as well as system locations. The @ConditionalOnResource annotation may be used on any class annotated with @Configuration , @Component , @Service & @Repository or on methods annotated with @Bean . 1. Using @ConditionalOnProperty on @Bean method and @Configuration class For example, The EmailNotificationService class is only loaded if the notification configuration file ( notification.properties ) was found on the classpath. The TwitterNotificationService class is only loaded if the notification and message configuration files ( notification.properties and message.properties ) was found on the classpath . @Configuration @ConditionalOnResource (resources = { "notifi...