Complete the code to enable basic actuator endpoints in a Spring Boot application.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
[1]
}The actuator starter adds monitoring endpoints to your Spring Boot app.
Complete the property to expose all actuator endpoints over HTTP.
management.endpoints.web.exposure.include=[1]Using '*' exposes all actuator endpoints for monitoring.
Fix the error in the code to create a custom health indicator bean.
@Component public class CustomHealthIndicator implements HealthIndicator { @Override public Health health() { return Health.[1]().withDetail("status", "All good").build(); } }
The 'up()' method indicates the service is healthy.
Fill both blanks to configure a custom endpoint path and enable it.
management.endpoints.web.base-path=[1] management.endpoint.health.enabled=[2]
Setting base-path to '/monitoring' changes the URL prefix.
Enabling health endpoint with 'true' makes it accessible.
Fill all three blanks to create a REST controller that returns application health status.
import org.springframework.web.bind.annotation.[1]; @RestController public class HealthController { private final HealthEndpoint healthEndpoint; public HealthController(HealthEndpoint healthEndpoint) { this.healthEndpoint = healthEndpoint; } @[2]("/custom-health") public Health health() { return healthEndpoint.[3](); } }
Import and annotate with @GetMapping for a GET endpoint.
Call health() on HealthEndpoint to get the status.