Sub topic 1
What Actuator provides and how to add it
Prerequisites
This chapter assumes you already know:
- How a Spring Boot application is structured and how auto-configuration works.
- How to add a dependency with Maven or Gradle.
- How to set properties in
application.yamlorapplication.properties. - Basic HTTP and JSON, enough to read a
curlresponse.
Spring Security knowledge is not needed here. It helps in the chapter on securing endpoints.
What Actuator provides
Spring Boot Actuator adds production-ready features to an application. It publishes endpoints, which are named resources that report on or change the running application. Each endpoint has an ID, such as health, and is usually served over HTTP at /actuator/<id>.
| Endpoint ID | What it shows |
|---|---|
| `health` | Whether the application and its dependencies are working |
| `info` | Application, build, and git details |
| `metrics` | Numbers such as memory use and request timings |
| `loggers` | Log levels, which you can also change at runtime |
| `env` | Configuration properties and the active environment |
| `mappings` | All request mappings in the application |
| `threaddump` | A snapshot of the JVM threads |
Later chapters cover each of these in detail. Here you only need to add Actuator and confirm it responds.
Adding Actuator
Actuator ships as a starter. Spring Boot's dependency management supplies the version, so you don't set one.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>The first dependency adds the endpoints. The second adds the Micrometer Prometheus registry, which provides the /actuator/prometheus endpoint. You can leave it out until you reach the metrics chapters.
In Gradle, the same dependencies look like this:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
}Checking that it works
Start the application and request the Actuator root. This is called the discovery page, and it lists the endpoints that are currently reachable.
curl http://localhost:8080/actuator{
"_links": {
"self": { "href": "http://localhost:8080/actuator", "templated": false },
"health": { "href": "http://localhost:8080/actuator/health", "templated": false },
"health-path": { "href": "http://localhost:8080/actuator/health/{*path}", "templated": true }
}
}Only health appears, even though many more endpoints exist. Request it directly:
curl http://localhost:8080/actuator/health{"status":"UP"}How it works
Actuator is auto-configured. Adding the starter to the classpath is enough for Spring Boot to register an endpoint bean for each feature. Each endpoint is separate from how it is delivered. The same endpoint can be served over HTTP and over JMX, and each of those channels has its own exposure rules.
The defaults are deliberately cautious. Over HTTP, only health is exposed. Other endpoints exist as beans but return 404 until you list them in management.endpoints.web.exposure.include. That setting is the subject of the next chapter.
Common errors
- 404 on
/actuator/metrics: the endpoint exists but is not exposed over HTTP. - 404 on
/actuator: the starter is missing from the build, or a custom base path is set. - Connection refused: a separate management port may be configured.
Exercise
You add spring-boot-starter-actuator to a project and start it with no extra configuration. You request /actuator/metrics and get a 404. Does that mean the metrics endpoint is missing? Why or why not?
Show answer
No. The endpoint bean exists after auto-configuration, but only health is exposed over HTTP by default. Add metrics to management.endpoints.web.exposure.include to make it reachable.