Bird
0
0

Identify the error in this custom actuator endpoint code:

medium📝 Debug Q14 of 15
Spring Boot - Actuator
Identify the error in this custom actuator endpoint code:
@Endpoint(id = "metrics")
public class MetricsEndpoint {
  @ReadOperation
  public String metrics() {
    return 12345;
  }
}
AThe @ReadOperation annotation is missing
BThe method name must be getMetrics
CThe @Endpoint annotation must be on a method, not class
DThe method declares String return type but returns an int
Step-by-Step Solution
Solution:
  1. Step 1: Check method return type consistency

    The method metrics() returns an integer literal 12345 but declares return type String, causing a type mismatch.
  2. Step 2: Verify annotations and method naming

    The @ReadOperation annotation is present, and @Endpoint is correctly on the class. Method name can be arbitrary.
  3. Final Answer:

    The method declares String return type but returns an int -> Option D
  4. Quick Check:

    Return type mismatch causes error [OK]
Quick Trick: Method return type must match declared type [OK]
Common Mistakes:
  • Thinking @Endpoint goes on methods
  • Assuming method name must follow getter pattern
  • Ignoring type mismatch errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes