This project is a Spring Boot application that demonstrates various features and best practices of the Spring Boot framework, including custom autoconfiguration, conditional bean loading, and actuator endpoints for monitoring and diagnostics.
-
Custom notification services (Email and SMS)
-
Conditional bean loading based on configuration properties
-
Spring Boot Actuator integration for runtime insights
To run the application, ensure you have Java and Maven installed. Clone the repository and run via your IDE or use the following command:
./mvnw spring-boot:run-
Add the starter dependency for Spring Boot Actuator. Verify that the dependency uses the autoconfiguration to open an endpoint: Start the application and go to
localhost:8080/actuator/health. -
Overwrite autoconfiguration and enable actuator endpoints in
application.yml: conditions, configprops, beans, env -
Run the app with logs in DEBUG mode to observe the condition report and
/actuator/conditionsendpoint:
-
Add the SMS properties to your
NotificationPropertiesconfiguration file -
Uncomment the lines in
SmsNotificationServiceto enable SMS sending simulation -
Configure conditional bean loading:
-
The EmailNotificationService is loaded by default and when
notification.type=email. -
The SmsNotificationService is loaded only if
notification.type=sms.
-
-
Check the Rest service defined in the
DemoController. Execute requests to this service to verify behavior. -
Verify also by changing the
notification.typeproperty and observing loaded beans in/actuator/conditionsand/actuator/beansendpoints.
Next we want to execute actions inside the bean lifecycle.
-
The
CustomAutoConfigurationshould log when it is constructed and destroyed -
Enable the shutdown endpoint
-
Verify the correct execution of the lifecycle hooks while starting and stopping the application via the shutdown endpoint
/actuator/shutdown
-
/actuator/conditions- Shows autoconfiguration condition evaluation report -
/actuator/beans- Lists all loaded beans -
/actuator/configprops- Displays configuration properties -
/actuator/env- Shows environment properties