skip to content

What are Spring Boot's built-in health indicators, and which ones does Actuator auto-register out of the box?

level: juniorimportance: must knowfreq 70%

answer

  1. ping = always UP
  2. diskSpace default 10MB threshold
  3. db = DataSourceHealthIndicator
  4. show-details defaults to never
  5. overall = worst status

basics

~10 s

Built-in health indicators are checks Actuator adds automatically to the /actuator/health endpoint. Common ones: PingHealthIndicator (always up), DiskSpaceHealthIndicator (free disk), DataSourceHealthIndicator (database), and RedisHealthIndicator when those libraries are present.

solid answer

~30 s

Spring Boot Actuator auto-configures a set of HealthIndicator beans that report component health at /actuator/health. Always present is PingHealthIndicator (a trivial 'app is alive' check) and DiskSpaceHealthIndicator (fails when free space drops below a threshold). Others are conditional on what's on the classpath and configured: DataSourceHealthIndicator (registered under the name 'db') runs a validation query against your DataSource; RedisHealthIndicator issues an INFO command to Redis. Each contributes a status (UP/DOWN/etc.) plus optional details. The overall endpoint status is the worst of all contributors. By default the endpoint shows only the top-level status; you enable per-component detail with management.endpoint.health.show-details=always (or when-authorized).

code

java · 14 lines
java
// application.properties
// Reveal per-component health in the endpoint body
// management.endpoint.health.show-details=always

// Example /actuator/health response with details on:
// {
//   "status": "UP",
//   "components": {
//     "db":        { "status": "UP", "details": { "database": "PostgreSQL", "validationQuery": "isValid()" } },
//     "diskSpace": { "status": "UP", "details": { "total": 500107862016, "free": 250053931008, "threshold": 10485760 } },
//     "ping":      { "status": "UP" },
//     "redis":     { "status": "UP", "details": { "version": "7.2.4" } }
//   }
// }

go deeper

for a junior

Know the four named indicators exist and that /health aggregates them; know show-details must be enabled to see components.

for a middle

Explain conditional registration by classpath, the naming scheme (db, diskSpace, ping, redis), and worst-status aggregation.

for a senior

Discuss show-details security tradeoffs (when-authorized), HTTP status mapping to 503, and how indicators feed probes.

for a principal

Frame health as an operational contract for orchestrators/LBs; reason about which checks belong in liveness vs readiness and blast radius of a DOWN dependency.

## What a health indicator is Spring Boot **Actuator** exposes an operational endpoint at `/actuator/health`. Its job is to answer 'is this application and its dependencies healthy?' The endpoint aggregates many **HealthIndicator** beans, each of which checks one thing (the database, disk, Redis, etc.) and returns a **Health** object carrying a **Status** (`UP`, `DOWN`, `OUT_OF_SERVICE`, `UNKNOWN`) plus an optional map of details. ## Which ones are auto-registered Actuator auto-configures indicators based on what's on the classpath (this is the whole point of Spring Boot auto-configuration — beans appear only when their supporting libraries and beans exist): - **PingHealthIndicator** — always registered. It does nothing but return `UP`. It's a cheap 'the web layer and Actuator are responding' signal. - **DiskSpaceHealthIndicator** — always registered. Checks free space on a configured path (default: the app's working directory) against a threshold (default **10 MB**). Returns `DOWN` when free space is below the threshold. - **DataSourceHealthIndicator** — registered when a `javax.sql.DataSource` bean exists. Its contributor name is **`db`**. It borrows a connection and runs a driver-appropriate validation query (e.g. `SELECT 1`). - **RedisHealthIndicator** — registered when Spring Data Redis and a `RedisConnectionFactory` are present. Issues Redis `INFO` and reports the server version. - Many more follow the same pattern: `MongoHealthIndicator`, `CassandraHealthIndicator`, `ElasticsearchHealthIndicator`, `RabbitHealthIndicator`, `MailHealthIndicator`, `LivenessStateHealthIndicator`/`ReadinessStateHealthIndicator`, etc. ## Naming Each indicator is registered under a **name** derived from its bean name with the `HealthIndicator` suffix stripped — `ping`, `diskSpace`, `db`, `redis`. That name is both the JSON key under `components` and the key used in the toggle properties (`management.health.<name>.enabled`). ## Seeing the details By default `/actuator/health` returns only `{"status":"UP"}` — no component breakdown — because `management.endpoint.health.show-details` defaults to `never`. Set it to `always` (or `when-authorized`, which only reveals details to authenticated/authorized users) to see per-indicator status and details. ## Overall status The endpoint's aggregate status is the **worst** individual status, ordered by a `StatusAggregator` (default worst→best: `DOWN`, `OUT_OF_SERVICE`, `UP`, `UNKNOWN`). A single `DOWN` component makes the whole endpoint `DOWN`, which by default maps to HTTP **503**. ## When to use Health indicators feed load balancers, container orchestrators (Kubernetes liveness/readiness probes), and monitoring. Understanding which are auto-registered tells you what your `/health` will report before you write any custom code.

  • Why does /actuator/health show only {"status":"UP"} by default with no components?
    Because management.endpoint.health.show-details defaults to 'never' to avoid leaking infrastructure detail to anonymous callers. Set it to 'always' or 'when-authorized' to expose the component breakdown.
  • If the database is down but ping is up, what does the overall endpoint report?
    DOWN. The aggregate status is the worst of all contributors, so one DOWN component (db) makes the whole endpoint DOWN, mapping to HTTP 503 by default.

saying these in an interview costs you the question

  • Thinking all health indicators (Mongo, Redis, DB) are always present regardless of classpath
  • Believing /actuator/health shows component details by default
  • Assuming overall status is 'UP' unless every check fails (it's actually the worst single status)

context