intermediate~2h

Spring Boot Actuator

"Is the service healthy?" is a question your infrastructure asks constantly, automatically. This module is the built-in feature that answers it, without you writing a single health-check line yourself.

Learning objectives

  • Beginner: Add the Actuator starter and hit the built-in /actuator/health endpoint.
  • Intermediate: Expose and secure specific Actuator endpoints for a production deployment.
  • Advanced: Write a custom HealthIndicator that reports on an application-specific dependency (e.g. a downstream API).

◆ The problem

Kubernetes needs to know if your pod is actually healthy before routing traffic to it (DevOps Mastery's Kubernetes book covers liveness/readiness probes in depth — they need SOMETHING to call), and an on-call engineer at 3am needs to see memory usage, active threads, and configuration without SSH-ing into a container.

Adding spring-boot-starter-actuator exposes a set of production-monitoring endpoints automatically — /actuator/health, /actuator/metrics, /actuator/info — without you writing a single line of monitoring code yourself.

management.endpoints.web.exposure.include=health,metrics,info

/actuator/health isn't one check — it's an aggregate of every HealthIndicator bean Spring Boot auto-detects, including built-in ones for your database connection pool, disk space, and Redis connection if those dependencies are on the classpath. If ANY indicator reports DOWN, the whole endpoint reports DOWN.

StatusMeaning
UPEverything this service depends on is reachable and healthy.
DOWNAt least one critical dependency (usually the database) is unreachable.
OUT_OF_SERVICEDeliberately marked unavailable (e.g. during a graceful shutdown).

This exact endpoint is what a Kubernetes readiness probe (DevOps Mastery's Kubernetes book) calls repeatedly — a DOWN response there means Kubernetes stops routing traffic to this pod instantly.

The built-in indicators check generic infrastructure (database, disk); they know nothing about YOUR application's specific dependencies, like a third-party payment API your checkout flow can't function without.

@Component public class PaymentGatewayHealthIndicator implements HealthIndicator { @Override public Health health() { boolean reachable = paymentClient.ping(); return reachable ? Health.up().withDetail("gateway", "reachable").build() : Health.down().withDetail("gateway", "unreachable").build(); } }

Once registered as a bean, Spring Boot automatically folds this into the aggregate /actuator/health response alongside the built-in checks — no extra wiring needed.

💻 Code example

@Component public class PaymentGatewayHealthIndicator implements HealthIndicator { @Override public Health health() { boolean reachable = paymentClient.ping(); return reachable ? Health.up().withDetail("gateway", "reachable").build() : Health.down().withDetail("gateway", "unreachable").build(); } }

▲ Pitfall

Exposing /actuator/env or /actuator/heapdump to the public internet is a real, commonly-exploited misconfiguration — /actuator/env can leak configuration values (sometimes including secrets), and /actuator/heapdump hands out a full memory dump an attacker can mine for credentials and session tokens.

Production configuration should expose only what's genuinely needed (health, info, metrics) and require authentication for anything sensitive, using the exact Spring Security patterns covered in that category:

.requestMatchers("/actuator/health").permitAll() .requestMatchers("/actuator/**").hasRole("ADMIN")

✓ Quick recap

  • Actuator exposes production-monitoring endpoints automatically once the starter is added.
  • /actuator/health aggregates every HealthIndicator bean — one DOWN makes the whole endpoint DOWN.
  • Write a custom HealthIndicator for application-specific dependencies the built-in checks don't know about.
  • Never expose sensitive Actuator endpoints (env, heapdump) without authentication in production.

Want a visual for this concept?

Generate a diagram tailored to “Spring Boot Actuator” — the AI picks whichever visual (flowchart, comparison, sequence, etc.) best fits.

Sign in to generate a visual →

Practice quiz

Next Step

Continue to Aspect-Oriented Programming (AOP)← Back to all Spring Boot chapters