Spring Boot: A custom HealthIndicator becomes part of /health

Implement the interface and the endpoint aggregates it - DOWN in any component makes the whole status DOWN.

Code
@Component
class PaymentGatewayHealth implements HealthIndicator {

    @Override
    public Health health() {
        try {
            gateway.ping();
            return Health.up().withDetail("gateway", "reachable").build();
        } catch (Exception e) {
            return Health.down(e).build();
        }
    }
}
Output
{"status":"DOWN","components":{"paymentGateway":{"status":"DOWN",
  "details":{"error":"java.net.ConnectException: refused"}}}}
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11