Bird
0
0

A developer tries to customize validation error responses by overriding the default BindingResult but gets a runtime error. What is a likely mistake?

medium📝 Debug Q7 of 15
Spring Boot - Exception Handling
A developer tries to customize validation error responses by overriding the default BindingResult but gets a runtime error. What is a likely mistake?
AMissing @ControllerAdvice annotation on the handler class
BNot adding @Valid before the request body parameter
CUsing @RequestParam instead of @RequestBody
DReturning ResponseEntity instead of String
Step-by-Step Solution
Solution:
  1. Step 1: Understand global handler setup

    To customize validation errors globally, the handler class must be annotated with @ControllerAdvice.
  2. Step 2: Identify cause of runtime error

    Without @ControllerAdvice, Spring does not recognize the handler, causing runtime errors when exceptions occur.
  3. Final Answer:

    Missing @ControllerAdvice annotation on the handler class -> Option A
  4. Quick Check:

    @ControllerAdvice is required for global exception handlers [OK]
Quick Trick: Use @ControllerAdvice for global validation error handlers [OK]
Common Mistakes:
  • Forgetting @ControllerAdvice on handler class
  • Missing @Valid on parameters
  • Mixing @RequestParam and @RequestBody

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes