Posts

Showing posts with the label @ConditionalOnExpression

Spring Boot @ConditionalOnExpression Annotation Example

Image
In this section we will learn about  @ConditionalOnExpression   Annotation. The  @ConditionalOnExpression  annotation allows configurations based on the result of a SpEL expression.  The  @ConditionalOnExpression  annotation may be used on any class annotated with @Configuration ,  @Component ,  @Service  &  @Repository  or on methods annotated with  @Bean . 1. Using @ConditionalOnExpression on @Bean method To illustrate the use of  @ConditionalOnExpression , we will develop a basic notification system. To keep things simple for now, let's assume we want to send email notifications and sms notifications. Define our application custom configuration properties, notification.enabled = true notification.sms.enabled = true notification.email.enabled = false notification.twitter.enabled = true Next,  we'll need to create a simple service to send a notification. For example, consider the Notification Sender interfac...