Skip to content

tinpa-de/spring-boot-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Lab

Overview

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.

Features

  • Custom notification services (Email and SMS)

  • Conditional bean loading based on configuration properties

  • Spring Boot Actuator integration for runtime insights

Getting Started

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

Tasks

Autoconfiguration Tasks

  1. 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.

  2. Overwrite autoconfiguration and enable actuator endpoints in application.yml: conditions, configprops, beans, env

  3. Run the app with logs in DEBUG mode to observe the condition report and /actuator/conditions endpoint:

Notification Service Configuration

  1. Add the SMS properties to your NotificationProperties configuration file

  2. Uncomment the lines in SmsNotificationService to enable SMS sending simulation

  3. Configure conditional bean loading:

    • The EmailNotificationService is loaded by default and when notification.type=email.

    • The SmsNotificationService is loaded only if notification.type=sms.

  4. Check the Rest service defined in the DemoController. Execute requests to this service to verify behavior.

  5. Verify also by changing the notification.type property and observing loaded beans in /actuator/conditions and /actuator/beans endpoints.

Bean lifecycle management

Next we want to execute actions inside the bean lifecycle.

  1. The CustomAutoConfiguration should log when it is constructed and destroyed

  2. Enable the shutdown endpoint

  3. Verify the correct execution of the lifecycle hooks while starting and stopping the application via the shutdown endpoint /actuator/shutdown

Useful Actuator Endpoints

  • /actuator/conditions - Shows autoconfiguration condition evaluation report

  • /actuator/beans - Lists all loaded beans

  • /actuator/configprops - Displays configuration properties

  • /actuator/env - Shows environment properties

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages