Loading...
Loading...
Configure Spring Boot Actuator for production-grade monitoring, health probes, secured management endpoints, and Micrometer metrics across JVM services.
npx skill4agent add giuseppe-trisciuoglio/developer-kit spring-boot-actuatorreferences/<!-- Maven -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>// Gradle
dependencies {
implementation "org.springframework.boot:spring-boot-starter-actuator"
}/actuator/health/actuator/info200 OKmanagement.endpoints.web.exposure.include"*"management.endpoints.web.base-path/management/actuatorreferences/endpoint-reference.mdSecurityFilterChainEndpointRequest.toAnyEndpoint()management.server.port/actuator/health/**management.endpoint.health.probes.enabled=true/health/liveness/health/readinessmanagement.endpoint.health.group.*HealthIndicatorReactiveHealthContributorreferences/examples.md#custom-health-indicatormanagement.metrics.export.*MeterRegistryCustomizerapplicationenvironmentserver.observation.*/actuator/startup/actuator/conditionsHttpExchangeRepositoryInMemoryHttpExchangeRepository/actuator/httpexchangesreferences/official-actuator-docs.mdmanagement:
endpoints:
web:
exposure:
include: "health,info"
endpoint:
health:
show-details: never@Component
public class PaymentsGatewayHealth implements HealthIndicator {
private final PaymentsClient client;
public PaymentsGatewayHealth(PaymentsClient client) {
this.client = client;
}
@Override
public Health health() {
boolean reachable = client.ping();
return reachable ? Health.up().withDetail("latencyMs", client.latency()).build()
: Health.down().withDetail("error", "Gateway timeout").build();
}
}management:
endpoint:
health:
probes:
enabled: true
group:
readiness:
include: "readinessState,db,paymentsGateway"
show-details: alwaysmanagement:
server:
port: 9091
ssl:
enabled: true
endpoints:
web:
exposure:
include: "health,info,metrics,prometheus"
base-path: "/management"
metrics:
export:
prometheus:
descriptions: true
step: 30s
endpoint:
health:
show-details: when-authorized
roles: "ENDPOINT_ADMIN"@Configuration
public class ActuatorSecurityConfig {
@Bean
SecurityFilterChain actuatorChain(HttpSecurity http) throws Exception {
http.securityMatcher(EndpointRequest.toAnyEndpoint())
.authorizeHttpRequests(c -> c
.requestMatchers(EndpointRequest.to("health")).permitAll()
.anyRequest().hasRole("ENDPOINT_ADMIN"))
.httpBasic(Customizer.withDefaults());
return http.build();
}
}references/examples.mdreferences/curl/actuator/env/actuator/configprops/actuator/logfile/actuator/heapdumpscripts/mvn spring-boot:run./gradlew bootRun/actuator/actuator/health/readinessUP/actuator/metrics/actuator/prometheushttp.server.requestsjvm.memory.used