Introduction
Spring Boot Actuator provides production-ready features to help you monitor and manage your application.
It exposes useful HTTP endpoints such as /actuator/health, /actuator/env, /actuator/beans and many more.
During this exercise we will add the Actuator to our CarApp and explore the available endpoints.
Learning objectives
-
Add the Actuator dependency to a Spring Boot project
-
Configure which endpoints are exposed
-
Use the Actuator endpoints to inspect the state of your application
Getting started
Step 1: Add the dependency
Add the following to your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
That is the only dependency needed. The old spring-boot-actuator-docs artifact no longer exists and is not required.
|
Step 2: Configure the endpoints
Add the following to your application.properties:
# Expose all actuator endpoints over HTTP (for development/training only!)
management.endpoints.web.exposure.include=*
# Show full health details (default is 'never')
management.endpoint.health.show-details=always
Exposing all endpoints with * is fine for development and training, but in production you should only expose the endpoints you actually need, e.g. management.endpoints.web.exposure.include=health,info,metrics. Sensitive endpoints like env, beans, and configprops can leak internal configuration details.
|
The base path for all actuator endpoints is /actuator by default. You can change this with management.endpoints.web.base-path=/manage if desired.
|
Step 3: Restart and explore
Restart the application and open Postman (or your browser).
Discover all available endpoints
This returns a list of all exposed endpoints with their URLs (HATEOAS style).
Useful endpoints to explore
| Endpoint | URL | Description |
|---|---|---|
health |
Shows application health status (UP/DOWN) and details about disk space, database, etc. |
|
info |
Shows application info (if configured in application.properties) |
|
beans |
Lists all Spring beans registered in the application context |
|
env |
Shows all environment properties (profiles, system properties, application.properties values) |
|
configprops |
Shows all |
|
metrics |
Lists all available metrics. Drill into a specific metric with |
|
mappings |
Shows all |
|
threaddump |
Shows a thread dump of the JVM |
|
loggers |
Shows and allows changing log levels at runtime |
Exercise
-
Open each of the endpoints listed above in Postman or your browser
-
Look at the health endpoint — what components does it report on?
-
Look at the beans endpoint — can you find your own CarController, CarService and CarRepository?
-
Look at the mappings endpoint — can you find all your REST endpoints?
-
Look at the metrics endpoint — open
/actuator/metrics/jvm.memory.usedto see the current JVM memory usage
-
Open
/actuator/envand find your database connection properties -
Try
/actuator/env/spring.datasource.urlto get a single property
-
Open
/actuator/loggers/com.acme.carappto see the current log level -
Use Postman to send a POST request to
/actuator/loggers/com.acme.carappwith the following JSON body to change the log level to DEBUG:
{
"configuredLevel": "DEBUG"
}
-
Verify by opening
/actuator/loggers/com.acme.carappagain — the level should now be DEBUG -
Make some requests to your CarController and observe the additional debug logging in the console
Takeaway
In this exercise, you learned how to add the Spring Boot Actuator to your project and explored the available endpoints for monitoring and managing your application. In a production environment, these endpoints are essential for health checking (e.g. in Kubernetes liveness/readiness probes) and observability.
Further reading
Production-ready Features - Spring Boot Reference |
https://docs.spring.io/spring-boot/reference/actuator/index.html |
Enabling Production-ready Features |
https://docs.spring.io/spring-boot/reference/actuator/enabling.html |
Spring Boot Actuator |