Make your app observable in production — expose health, info, and metrics endpoints with Actuator, add a custom health check, and record metrics with Micrometer.
Why: spring-boot-starter-actuator adds production-ready endpoints under /actuator — health, metrics, environment, mappings — without you writing any. Note: only /health and /info are exposed by default; you opt the rest in explicitly.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>Note: choose which endpoints are visible over HTTP. /actuator/health is what a load balancer or Kubernetes probe polls to know your app is alive; /actuator/metrics lists every metric being collected. Be selective in production — these reveal internals.
# application.properties — expose specific endpoints
management.endpoints.web.exposure.include=health,info,metrics,prometheus
management.endpoint.health.show-details=alwayscurl http://localhost:8080/actuator/health
curl http://localhost:8080/actuator/metrics/jvm.memory.usedWhen: you want /health to reflect a dependency Actuator cannot check itself — a downstream API, a queue. Note: implement HealthIndicator; returning down() flips the overall health to DOWN, which your orchestrator can act on.
@Component
public class PaymentHealthIndicator implements HealthIndicator {
@Override
public Health health() {
if (paymentGatewayReachable()) {
return Health.up().withDetail("gateway", "reachable").build();
}
return Health.down().withDetail("gateway", "unreachable").build();
}
}Why: Micrometer is the metrics facade behind Actuator — it records counters, timers, and gauges and ships them to monitoring systems (Prometheus, Datadog) by adding a registry dependency. When a Counter: count business events like books sold.
@Service
public class SalesService {
private final Counter booksSold;
public SalesService(MeterRegistry registry) {
this.booksSold = registry.counter("books.sold");
}
public void sell(Book book) {
// ... process the sale ...
booksSold.increment(); // shows up under /actuator/metrics
}
}