Implement the interface and the endpoint aggregates it - DOWN in any component makes the whole status DOWN.
@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();
}
}
}
{"status":"DOWN","components":{"paymentGateway":{"status":"DOWN",
"details":{"error":"java.net.ConnectException: refused"}}}}
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