Skip to lesson

Health checks with Spring Boot Actuator

A load balancer must decide whether to send customers to this copy of ShopLite. If it can only check that the port is open, an app with a dead database still looks healthy.

Adding Actuator and calling /actuator/health

Spring Boot Actuator is a Boot module that adds ready-made endpoints, such as /actuator/health, which tell other programs how the running app is doing.

spring-boot-starter-actuator is one dependency; with it, every Boot web app gets /actuator/health. The answer is JSON with a status, and the HTTP code matches it: 200 for UP, 503 for DOWN.

Example 1 · pom.xml: the Actuator starter, and the default health answer

Runs in: the config-lab practice project with Spring Web MVC, Actuator, JDBC and the ShopLite database

XML
<!-- pom.xml, inside <dependencies> --><dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-actuator</artifactId></dependency>
Sample output
$ curl -i localhost:8080/actuator/health
HTTP/1.1 200 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{"groups":["liveness","readiness"],"status":"UP"}

$ curl -i localhost:8080/actuator
HTTP/1.1 200 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{"_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}}}

$ curl -i localhost:8080/actuator/env
HTTP/1.1 404 
Content-Type: application/json

{"timestamp":"2026-10-16T06:57:55.207Z","status":404,"error":"Not Found","path":"/actuator/env"}

What this code does

  • With no Actuator settings, /actuator/health shows only the overall status and the names of the two probe groups. /actuator lists what is exposed: just health.
  • /actuator/env answers 404: the endpoint exists but is not exposed over HTTP. The 404 body is Boot's default error JSON, because config-lab has no ProblemDetail handler.
  • In Windows PowerShell 5.1, curl is a short name for Invoke-WebRequest; type curl.exe -i ... there to run the real curl.

Why does an API need this? On a server, something must decide whether to send traffic to your app and whether to restart it. Without a health endpoint, that tool can only check that the port is open, and an app with a dead database connection still looks fine.

The lessons from here on run config-lab as a web app: add spring-boot-starter-webmvc and spring-boot-starter-actuator to its pom.xml, next to the JDBC dependencies from the secrets lesson, and start it with the DB_* variables set.

Exposing only the endpoints you need

Over HTTP, Boot exposes only health by default; the other endpoints answer 404. management.endpoints.web.exposure.include=health,info names exactly what is reachable.

Example 2 · Exposing health and info, nothing else

Runs in: the config-lab practice project with Spring Web MVC, Actuator, JDBC and the ShopLite database

Properties
# src/main/resources/application.properties# Actuator: only health and info over HTTPmanagement.endpoints.web.exposure.include=health,info
Sample output
$ curl -i localhost:8080/actuator
HTTP/1.1 200 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"info":{"href":"http://localhost:8080/actuator/info","templated":false},"health":{"href":"http://localhost:8080/actuator/health","templated":false},"health-path":{"href":"http://localhost:8080/actuator/health/{*path}","templated":true}}}

$ curl -i localhost:8080/actuator/env
HTTP/1.1 404 
Content-Type: application/json

{"timestamp":"2026-10-16T06:58:18.094Z","status":404,"error":"Not Found","path":"/actuator/env"}

What this code does

  • The links list now has info and health. env is still 404, so nobody can read your settings over HTTP.
  • The setting takes a comma-separated list of endpoint ids. exclude also exists and wins over include.

Actuator has many more endpoints: env (every setting), configprops, beans, loggers, heapdump (a copy of the JVM memory), threaddump, shutdown and others. Keep the list short in prod: env and configprops show settings, and a heap dump can contain passwords, tokens and customer data that happened to be in memory. Never use include=* on a public server.

When you need the powerful endpoints, expose them only on a separate port that is not reachable from the internet (management.server.port), or protect them with Spring Security, which comes in a later section.

Fix the error

Fix the exposure setting

Each setting causes a problem. Pick the line that replaces the marked one.

Round 1 of 3

The deployment tool needs /actuator/info, but it answers 404.

management.endpoints.web.exposure.include=health
management.endpoint.health.show-details=never

Error

GET /actuator/info -> 404 Not Found

Health details and the database health indicator

A health indicator is a bean that checks one thing, such as the database, and reports a status. The overall /actuator/health status is the worst of all indicators.

Boot adds indicators automatically for what it finds: db when a DataSource exists, diskSpace, ping and more. management.endpoint.health.show-details decides how much of them you see.

The /actuator/health answer is built from several health indicators. The db indicator is UP, the diskSpace indicator is UP, and a custom invoiceFolder indicator is DOWN. The overall status is the worst of them, so it is DOWN, and the HTTP code is 503.

Example 3 · show-details=always: the db component and its friends

Runs in: the config-lab practice project with Spring Web MVC, Actuator, JDBC and the ShopLite database

Properties
# src/main/resources/application.properties (dev values)spring.datasource.hikari.connection-timeout=3000management.endpoint.health.show-details=always
Sample output
$ curl -i localhost:8080/actuator/health
HTTP/1.1 200 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{
  "components": {
    "db": {
      "details": {
        "database": "MySQL",
        "validationQuery": "isValid()"
      },
      "status": "UP"
    },
    "diskSpace": {
      "details": {
        "total": 237483585536,
        "free": 29909639168,
        "threshold": 10485760,
        "path": "...",
        "exists": true
      },
      "status": "UP"
    },
    "invoiceFolder": {
      "details": {
        "folder": "invoices"
      },
      "status": "UP"
    },
    "livenessState": {
      "status": "UP"
    },
    "ping": {
      "status": "UP"
    },
    "readinessState": {
      "status": "UP"
    },
    "ssl": {
      "details": {
        "expiringChains": [],
        "invalidChains": [],
        "validChains": []
      },
      "status": "UP"
    }
  },
  "groups": [
    "liveness",
    "readiness"
  ],
  "status": "UP"
}

$ curl -i localhost:8080/actuator/health/db
HTTP/1.1 200 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{
  "details": {
    "database": "MySQL",
    "validationQuery": "isValid()"
  },
  "status": "UP"
}

# Later, with DB_URL pointing to a port where no MySQL runs:
$ curl -i localhost:8080/actuator/health/db
HTTP/1.1 503 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{"details":{"error":"org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection"},"status":"DOWN"}

What this code does

  • The JSON is shown formatted (curl prints it on one line) and the disk path is shortened. db says MySQL answered; invoiceFolder is the custom indicator from Example 6.
  • When MySQL cannot be reached, db is DOWN with the error and the HTTP status is 503. The short connection-timeout (3 s) makes the check fail fast instead of waiting 30 s.
  • Without show-details=always the same app shows only {"groups":[...],"status":"UP"}, and /actuator/health/db is a 404.

The db indicator borrows a connection and checks it is valid; others cover disk space, ssl and the liveness and readiness states. show-details takes never (the default: only the overall status), when-authorized (details only for authenticated users) or always.

Use always in dev; in prod use never or when-authorized, because details reveal your database type and internal errors. Each component also has its own URL, such as /actuator/health/db. With details hidden, those sub-paths answer 404.

/actuator/info: version and Git commit

/actuator/info shows facts about the running build: artifact, version and build time from the Maven plugin's build-info goal, and the Git branch and short commit id from git-commit-id-maven-plugin.

Example 4 · pom.xml plugins and info.* settings for /actuator/info

Runs in: the config-lab practice project with Spring Web MVC, Actuator, JDBC and the ShopLite database

Text
# pom.xml<!-- pom.xml, inside <build><plugins> --><plugin>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-maven-plugin</artifactId>    <executions>        <execution>            <goals>                <goal>build-info</goal>   <!-- writes META-INF/build-info.properties -->            </goals>        </execution>    </executions></plugin><plugin>    <!-- writes git.properties; the version comes from the Spring Boot parent -->    <groupId>io.github.git-commit-id</groupId>    <artifactId>git-commit-id-maven-plugin</artifactId></plugin># src/main/resources/application.propertiesmanagement.info.env.enabled=trueinfo.app.description=ShopLite configuration labinfo.app.java-version=${java.specification.version}
Sample output
$ curl -i localhost:8080/actuator/info
HTTP/1.1 200 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{
  "app": {
    "description": "ShopLite configuration lab",
    "java-version": "19"
  },
  "git": {
    "branch": "master",
    "commit": {
      "id": "1175684",
      "time": "2026-10-16T05:19:10Z"
    }
  },
  "build": {
    "artifact": "config-lab",
    "name": "config-lab",
    "time": "2026-10-16T05:21:08.366Z",
    "version": "0.0.1-SNAPSHOT",
    "group": "com.shoplite"
  }
}

What this code does

  • build comes from build-info.properties and git from git.properties; both files are written into the jar by ./mvnw package. The Git plugin needs the project to be a Git repository with at least one commit.
  • app comes from the info.app.* settings (the second file). java-version shows the Java that runs the jar: 17 or 21 on your computer.
  • The commit id 1175684 is the short hash of the commit the jar was built from; compare it with git log --oneline.

The info endpoint must be in the exposure list. It answers a classic production question: "which version is running on the server right now?" If a bug appears after a deploy, the commit id tells you exactly which code to look at.

management.info.env.enabled=true also shows every info.* setting, such as info.app.description. Like any setting, they can use placeholders, for example ${java.specification.version}.

Liveness, readiness and a custom HealthIndicator

Liveness asks whether the app is broken beyond repair, so a platform should restart it. Readiness asks whether the app may receive traffic right now.

Deployment platforms such as Kubernetes ask two questions: should this app be restarted, and may it receive traffic? Boot 4.1 serves /actuator/health/liveness and /actuator/health/readiness out of the box.

Example 5 · Liveness and readiness while the database is down

Runs in: the config-lab practice project with Spring Web MVC, Actuator, JDBC and the ShopLite database

Properties
# Started with the database unreachable (DB_URL points to a port with no MySQL)# and this setting, so readiness also checks the database:management.endpoint.health.group.readiness.include=readinessState,db
Sample output
$ curl -i localhost:8080/actuator/health/db
HTTP/1.1 503 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{
  "details": {
    "error": "org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection"
  },
  "status": "DOWN"
}

$ curl -i localhost:8080/actuator/health/liveness
HTTP/1.1 200 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{
  "status": "UP"
}

$ curl -i localhost:8080/actuator/health/readiness
HTTP/1.1 503 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{
  "components": {
    "db": {
      "details": {
        "error": "org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection"
      },
      "status": "DOWN"
    },
    "readinessState": {
      "status": "UP"
    }
  },
  "status": "DOWN"
}

What this code does

  • Liveness stays 200: the app itself is fine, so a platform would not restart it.
  • Readiness is 503 because the group now includes db: a load balancer stops sending requests to this copy until MySQL is back, then readiness turns UP again on its own.

Example 6 · InvoiceFolderHealthIndicator.java: a custom check

Runs in: the config-lab practice project with Spring Web MVC, Actuator, JDBC and the ShopLite database

InvoiceFolderHealthIndicator.javaJava
// src/main/java/com/shoplite/lab/health/InvoiceFolderHealthIndicator.javapackage com.shoplite.lab.health;
import java.nio.file.Files;import java.nio.file.Path;
import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.health.contributor.Health;import org.springframework.boot.health.contributor.HealthIndicator;import org.springframework.stereotype.Component;
@Componentpublic class InvoiceFolderHealthIndicator implements HealthIndicator {
    private final Path folder;
    public InvoiceFolderHealthIndicator(@Value("${shoplite.invoice-dir:invoices}") String folder) {        this.folder = Path.of(folder);    }
    @Override    public Health health() {        if (Files.isDirectory(folder) && Files.isWritable(folder)) {            return Health.up().withDetail("folder", folder.toString()).build();        }        return Health.down()                .withDetail("folder", folder.toString())                .withDetail("reason", "missing or not writable, so invoices cannot be saved")                .build();    }}
Sample output
# With the folder present (part of /actuator/health):
"invoiceFolder": { "details": { "folder": "invoices" }, "status": "UP" }

# After deleting the invoices folder:
$ curl -i localhost:8080/actuator/health/invoiceFolder
HTTP/1.1 503 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{"details":{"folder":"invoices","reason":"missing or not writable, so invoices cannot be saved"},"status":"DOWN"}

$ curl -i localhost:8080/actuator/health/readiness
HTTP/1.1 200 
Content-Type: application/vnd.spring-boot.actuator.v3+json

{"status":"UP"}

What this code does

  • Spring finds the bean like any @Component; its name invoiceFolderHealthIndicator gives the component name invoiceFolder and the URL /actuator/health/invoiceFolder.
  • When the folder is missing, the component is DOWN with a reason, and the overall /actuator/health becomes DOWN with HTTP 503 as well.
  • Readiness stays UP because the readiness group does not include this component. Add it to the group only if the app truly cannot serve requests without it.

By default both groups check only the app's own state, not the database. If an instance without a database should get no traffic, add the check to readiness only: management.endpoint.health.group.readiness.include=readinessState,db. Never add outside systems to liveness, or a short database outage restarts every copy of your app at once.

For anything your app depends on, write a custom HealthIndicator: a bean with one health() method that returns Health.up(), Health.down() or Health.outOfService() with details. In Boot 4 the interface is org.springframework.boot.health.contributor.HealthIndicator; the bean name minus HealthIndicator becomes the component name.

Predict the output

Which HTTP code?

Read the setup, then pick the answer a platform would see.

Round 1 of 3

MySQL is stopped. What do the two probes return?

# default settings, MySQL is down
GET /actuator/health/liveness
GET /actuator/health/readiness

Next step

Check your understanding

11 quick questions