Custom Bean Instantiation Using @ConditionalOnProperty Annotation in Spring Boot
Spring boot is a widely used framework to bootstrap standalone web applications. Its flexibility and capabilities in beans management make the life of the developer much easier compared to the manual handling of these components.
In this blog post, I will describe a use case where I needed the help of Spring Boot to create beans based on a configuration set in my application.yml
file.
Problem Description
I was working on a notification service where depending on events received and the configuration set up, notifications of different types were sent to users. These notifications were emails, SMS messages and push notifications for mobile applications.
The usage of SMS messages increased and this impacted the bill that the company had to pay to the third party which is Twilio.
Because of that, we decided to look for another third-party tool that can send SMS messages but at cheaper prices, and the decision was made to use the AWS SNS service since the notification service is already running on AWS.
At this point we should have no problem doing this replacement, it’s just a matter of coding a new SMS provider for our service and replacing the old one.