You want to create a custom actuator endpoint that returns a map of application info with keys "version" and "status". Which code snippet correctly implements this?
hard📝 component behavior Q8 of 15
Spring Boot - Actuator
You want to create a custom actuator endpoint that returns a map of application info with keys "version" and "status". Which code snippet correctly implements this?
A@Component
@Endpoint(id = "appinfo")
public class AppInfoEndpoint {
@ReadOperation
public Map<String, String> info() {
return Map.of("version", "1.0", "status", "running");
}
}
B@Component
@Endpoint(id = "appinfo")
public class AppInfoEndpoint {
public Map<String, String> info() {
return Map.of("version", "1.0", "status", "running");
}
}
C@Endpoint(id = "appinfo")
public class AppInfoEndpoint {
@ReadOperation
public String info() {
return "version:1.0, status:running";
}
}
D@Component
@RestController
public class AppInfoEndpoint {
@GetMapping("/actuator/appinfo")
public Map<String, String> info() {
return Map.of("version", "1.0", "status", "running");
}
}
Step-by-Step Solution
Solution:
Step 1: Check annotations for custom actuator endpoint
Use @Component and @Endpoint(id=...) to define the endpoint bean.
Step 2: Ensure method is exposed
Method must have @ReadOperation and return Map for key-value info.
Final Answer:
Option A correctly defines the endpoint with proper annotations and return type -> Option A
Quick Check:
Custom endpoint with map data = @Component + @Endpoint + @ReadOperation [OK]
Quick Trick:Use @ReadOperation and return Map for key-value actuator data [OK]
Common Mistakes:
Omitting @ReadOperation on method
Using @RestController instead of @Endpoint
Returning String instead of Map for structured data
Master "Actuator" in Spring Boot
9 interactive learning modes - each teaches the same concept differently