Sub topic 5
Health endpoints with Actuator
This chapter assumes you can build a Spring Boot application with Maven or Gradle, run its executable JAR, and read basic HTTP status codes. It covers how Spring Boot Actuator reports whether the application is alive and ready for traffic. Later chapters use these endpoints in systemd and Kubernetes.
Why a running process is not enough
A JVM process can be running while the application is unusable. It may still be starting up, or it may have lost its database connection. A deployment tool that only checks the process cannot tell the difference. It needs an HTTP endpoint that answers one question: should this instance receive traffic?
Spring Boot Actuator provides those endpoints. Add the starter to your build:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>In Gradle, the same dependency is implementation 'org.springframework.boot:spring-boot-starter-actuator'.
Configuring the endpoints
Add these properties to the packaged application.properties:
management.endpoint.health.probes.enabled=true
management.endpoints.web.exposure.include=health,infoThe first line turns on the probe endpoints. The second line chooses which Actuator endpoints are reachable over HTTP. Only health and info are exposed here. Other endpoints, such as env or heapdump, can reveal sensitive data, so expose them only when you need them and protect them.
Start the application and request the health endpoint:
curl -i http://localhost:8080/actuator/healthA healthy application answers with status 200 and a body like this:
{"status":"UP"}If a critical check fails, the status is DOWN and the HTTP response code is 503.
Liveness and readiness
With probes enabled, Actuator adds two groups under the health endpoint:
| Path | Question it answers | Typical use |
|---|---|---|
| `/actuator/health/liveness` | Is the application in a working state, or should it be restarted? | Restart a stuck instance |
| `/actuator/health/readiness` | Can the application accept traffic right now? | Add or remove the instance from load balancing |
The two differ in what a failure means. A failed liveness check says the process is broken beyond recovery, and restarting it is the fix. A failed readiness check says the instance is temporarily unable to serve, for example during startup or shutdown, and the right response is to stop sending requests to it and wait.
Behind these paths is the application's availability state. Spring Boot sets readiness to REFUSING_TRAFFIC until startup finishes and again when shutdown begins.
The next chapter covers the draining step in detail.
What the health status includes
The /actuator/health endpoint combines the results of individual health indicators. Spring Boot registers indicators automatically for the components it detects, such as the database DataSource, disk space, and some message brokers. If any indicator reports DOWN, the overall status is DOWN.
By default, the response shows only the overall status. To see the individual components while debugging, set:
management.endpoint.health.show-details=when-authorizedAvoid always on a public port. Component details can expose hostnames and internal structure.
Common errors
- 404 on
/actuator/health. The starter is missing from the build, or a differentmanagement.endpoints.web.base-pathis configured. - Only
/actuator/healthworks, not/liveness. Probes are not enabled. Outside Kubernetes they are enabled automatically only when Spring Boot detects a Kubernetes environment, so set the property explicitly. - The database in a readiness check. By default, readiness does not include external systems. If a database outage makes every instance fail readiness, the whole service goes out of rotation. Keep external dependencies out of liveness, and add them to readiness only when you have thought through that effect.
- Restart loops. A liveness check that depends on a slow downstream service can cause restarts that do not help.
Exercise
Your application is running but is overloaded for a few seconds and cannot take new requests. Should this affect the liveness probe or the readiness probe, and why?
Show answer
The readiness probe. The instance is healthy and will recover, so restarting it (what a liveness failure triggers) would only make things worse. Failing readiness removes it from load balancing until it can serve requests again.
Exercise
Which two properties make /actuator/health/liveness and /actuator/health/readiness available over HTTP in the packaged application?
Show answer
management.endpoint.health.probes.enabled=true enables the probe groups, and management.endpoints.web.exposure.include=health,info (or any list that includes health) exposes the health endpoint over HTTP.