Spring Boot Actuator and Custom Endpoints

Production endpoints with Spring Boot Actuator: health (groups, liveness and readiness probes for Kubernetes), metrics and Prometheus, info, loggers, env, configprops, threaddump, heapdump, SBOM; exposing and securing endpoints on a separate port; custom HealthIndicators, InfoContributors and @Endpoint operations.

On this page

Simple definition#

Spring Boot Actuator adds production-ready endpoints that show whether an application is healthy, what it is doing, and how it is configured: health, metrics, info, loggers, environment, thread dumps and more. You can add your own health checks and endpoints.

The problem#

Operators and platforms need standard answers: is it alive? Is it ready for traffic? How busy is it? Which version is deployed? Can I raise a log level without redeploying? Writing these per service is wasteful and inconsistent.

Key endpoints#

EndpointShows / doesExpose in production?
/actuator/healthUP, DOWN or OUT_OF_SERVICE, plus components (db, disk, broker)✅ (details only to authorised users)
/actuator/health/liveness, /readinessKubernetes probe groups✅
/actuator/infoBuild, Git, Java and OS info✅
/actuator/metrics, /actuator/prometheusMicrometer metrics✅ (scrape on the internal port)
/actuator/loggersView or change log levels at runtime🔒 Admin only
/actuator/env, /configpropsConfiguration (values sanitised)🔒 Admin only
/actuator/threaddump, /heapdumpDiagnostics🔒 Admin only (a heap dump contains data)
/actuator/conditions, /beans, /mappingsContainer introspection🔒 / dev
/actuator/sbomSoftware bill of materials (CycloneDX)🔒
/actuator/shutdownStops the app❌ Disabled by default

Configuration#

management:
  server:
    port: 8081                                   # separate port, not exposed via the ingress
  endpoints:
    web:
      exposure:
        include: health, info, prometheus, loggers
  endpoint:
    health:
      show-details: when-authorized
      probes:
        enabled: true                            # auto-enabled on Kubernetes
      group:
        readiness:
          include: readinessState, db, kafka     # ready only when dependencies are usable
  info:
    git.mode: simple
    env.enabled: true
info:
  app:
    team: payments

Security: use a separate management port that is not routed publicly, plus a SecurityFilterChain that permits /actuator/health/** and /actuator/info and requires an admin role for the rest. See security filter chain.

Health, liveness and readiness#

Kubernetes probes backed by Actuator
flowchart LR
    K["kubelet"] -->|"livenessProbe"| L["/actuator/health/liveness<br/>LivenessState only"]
    K -->|"readinessProbe"| R["/actuator/health/readiness<br/>ReadinessState + db + broker"]
    L -->|"DOWN"| RESTART["restart container"]
    R -->|"DOWN"| OUT["remove from Service endpoints"]

Spring Boot publishes AvailabilityChangeEvents. During graceful shutdown readiness goes to REFUSING_TRAFFIC, and you can change it yourself.

Custom health indicator#

@Component("paymentProvider")
class PaymentProviderHealth implements HealthIndicator {
    private final PaymentClient client;
    PaymentProviderHealth(PaymentClient client) { this.client = client; }

    @Override
    public Health health() {
        try {
            Duration latency = client.ping();                  // keep it fast; use timeouts
            return Health.up().withDetail("latencyMs", latency.toMillis()).build();
        } catch (Exception e) {
            return Health.down(e).build();
        }
    }
}

Health checks run on every probe call, so keep them cheap and time-bounded. Cache expensive checks. Group them deliberately.

Custom info#

@Component
class FeatureFlagsInfo implements InfoContributor {
    public void contribute(Info.Builder b) { b.withDetail("features", Map.of("newCheckout", true)); }
}

Also add the spring-boot-maven-plugin build-info goal and the git-commit-id plugin so /info shows the version and commit.

Custom endpoints#

@Component
@Endpoint(id = "featureflags")                       // /actuator/featureflags (web and JMX)
class FeatureFlagsEndpoint {
    private final Map<String, Boolean> flags = new ConcurrentHashMap<>();

    @ReadOperation                                    // GET
    Map<String, Boolean> all() { return flags; }

    @ReadOperation                                    // GET /actuator/featureflags/{name}
    Boolean one(@Selector String name) { return flags.get(name); }

    @WriteOperation                                   // POST with a JSON body
    void set(@Selector String name, boolean enabled) { flags.put(name, enabled); }

    @DeleteOperation                                  // DELETE
    void remove(@Selector String name) { flags.remove(name); }
}
  • @Endpoint is technology-neutral (HTTP and JMX). @WebEndpoint and @JmxEndpoint restrict it to one.
  • Expose it explicitly (management.endpoints.web.exposure.include=featureflags) and secure it.
  • Endpoint access control (management.endpoint.<id>.access=read-only|unrestricted|none) replaced the old enabled flags in Boot 3.4+.

Metrics, tracing and logs#

Actuator auto-configures Micrometer: JVM, HTTP server and client, datasource, cache, executor and Kafka metrics, plus the Observation API for tracing. See observability with Micrometer and OpenTelemetry.

Common mistakes#

Quick check#

Liveness vs readiness? Liveness answers “is the process OK, or should it be restarted?”. Readiness answers “can it serve traffic now?”. External dependencies belong in readiness.

How do you add a custom health check? Implement HealthIndicator (or ReactiveHealthIndicator) as a bean. It appears as a component of /actuator/health.

How do you create a custom actuator endpoint? Annotate a bean with @Endpoint(id = …) and add @ReadOperation, @WriteOperation or @DeleteOperation methods, then expose and secure it.

Which endpoints must never be public? env, configprops, heapdump, threaddump, loggers (write), shutdown and other admin endpoints.

Why use a separate management port? So actuator endpoints are not reachable through the public ingress, and can have different network and security rules.

Summary#

  • Actuator standardises health, info, metrics and diagnostics.
  • Liveness checks own state; readiness checks dependencies; probes are auto-enabled on Kubernetes.
  • Expose little, on a separate port, behind authorisation.
  • Extend with HealthIndicator, InfoContributor and @Endpoint.

References#