Complete the code to define a custom actuator endpoint class.
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; @[1](id = "custom") public class CustomEndpoint { @ReadOperation public String custom() { return "Hello from custom endpoint!"; } }
The @Endpoint annotation marks the class as a custom actuator endpoint with the given id.
Complete the code to register the custom endpoint as a Spring bean.
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class EndpointConfig { @Bean public CustomEndpoint [1]() { return new CustomEndpoint(); } }
The bean method name is usually the camelCase version of the class name, here customEndpoint.
Fix the error in the method that exposes the endpoint data.
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; public class CustomEndpoint { @ReadOperation public String [1]() { return "Custom data"; } }
The method name can be any valid name, but to match the example and avoid confusion, use custom.
Fill both blanks to create a custom actuator endpoint that returns a map with status and message.
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import java.util.Map; @[1](id = "status") public class StatusEndpoint { @[2] public Map<String, String> status() { return Map.of("status", "UP", "message", "All systems go"); } }
The class must be annotated with @Endpoint and the method with @ReadOperation to expose the data.
Fill all three blanks to create a custom actuator endpoint that accepts a path variable and returns a greeting message.
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.Selector; @[1](id = "greet") public class GreetEndpoint { @[2] public String greet(@[3] String name) { return "Hello, " + name + "!"; } }
The class uses @Endpoint, the method uses @ReadOperation, and the parameter uses @Selector to accept a path variable.