Bird
0
0

Consider this Spring Boot controller method:

medium📝 component behavior Q4 of 15
Spring Boot - Exception Handling
Consider this Spring Boot controller method:
@PostMapping("/register")
public ResponseEntity registerUser(@Valid @RequestBody User user) {
    return ResponseEntity.ok("Registration successful");
}
If the User object has a @NotBlank field 'email' and the client sends an empty email, what will the HTTP response contain?
AHTTP 404 status indicating resource not found
BHTTP 200 status with "Registration successful" message
CHTTP 500 status with server error stack trace
DHTTP 400 status with a default validation error message in the response body
Step-by-Step Solution
Solution:
  1. Step 1: Recognize validation failure

    Empty 'email' violates @NotBlank, triggering validation failure.
  2. Step 2: Default Spring Boot behavior

    Spring Boot returns HTTP 400 Bad Request with a default error message describing the validation issue.
  3. Final Answer:

    HTTP 400 status with a default validation error message in the response body is correct.
  4. Quick Check:

    Validation failure returns 400 with error details [OK]
Quick Trick: Invalid input triggers 400 with validation error message [OK]
Common Mistakes:
  • Assuming 200 OK despite validation failure
  • Expecting 500 Internal Server Error for validation issues
  • Confusing 404 Not Found with validation errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes