Scrivio Interview library
InternalsIntermediate6 min read · updated 12 November 2026

What exceptions are thrown when validation fails for a @RequestBody, a @ModelAttribute and a @RequestParam with @Min, in Spring Framework 6.1 and later?

A failed @Valid @RequestBody throws MethodArgumentNotValidException, and a failed @Valid @ModelAttribute throws the same exception, which is a subclass of BindException. Since Spring Framework 6.1, a constraint placed directly on a parameter, such as @Min(1) on a @RequestParam, triggers built-in method validation and HandlerMethodValidationException, all of these answering 400. If the controller class carries @Validated, AOP method validation runs instead and throws ConstraintViolationException, which is 500 unless handled, so Spring recommends not combining class-level @Validated with the built-in support.

Background to this question

Validation errors are only useful if they reach the client as a clear 400 with field details. That depends on catching the right exception, and Spring Framework 6.1 changed which exception that is for some parameters. Teams upgrading from older versions find their @ControllerAdvice suddenly misses errors, or find that @RequestParam constraints which never worked now produce a new exception type. In this answer, we will recap the two validation mechanisms in Spring MVC, then look at each of the three cases, see what changed in 6.1, and write one exception handler that covers them all.

1A Quick Recap of the Two Mechanisms

Spring MVC has two ways to validate controller input. The first is argument validation: an argument resolver, the component that turns the request into a method parameter, binds a @RequestBody or @ModelAttribute object and then validates it if it carries @Valid or @Validated. Failures become a BindingResult, a container of field errors, wrapped in an exception.

The second is method validation: checking constraints declared directly on method parameters, such as @Min(1) int page, the way the Jakarta Validation method API does. Before 6.1, Spring MVC only offered this through AOP, by putting @Validated on the controller class so a proxy checked each call. Since 6.1, Spring MVC has built-in method validation for controllers, which needs no proxy and turns on by itself when a parameter has a constraint annotation.

Which exception for which case (Spring 6.1 and later)
ParameterMechanismExceptionDefault status
@Valid @RequestBodyargument resolverMethodArgumentNotValidException400
@Valid @ModelAttributeargument resolverMethodArgumentNotValidException400
@RequestParam @Min(1)built-in method validationHandlerMethodValidationException400
any, with @Validated on the classAOP proxyConstraintViolationException500

2@RequestBody and @ModelAttribute

For a JSON body or a form-bound object, the argument resolver validates after binding. If there are violations and the method has no BindingResult parameter right after the argument, it throws MethodArgumentNotValidException.

Java
@PostMapping("/orders")
OrderDto create(@Valid @RequestBody OrderRequest body) { ... }
// POST {"quantity": 0} -> MethodArgumentNotValidException, 400
@GetMapping("/orders")
List<OrderDto> search(@Valid @ModelAttribute OrderFilter filter) { ... }
// GET /orders?minTotal=-5 -> MethodArgumentNotValidException, 400
@GetMapping("/orders/legacy")
List<OrderDto> legacy(@Valid OrderFilter filter, BindingResult result) { ... }
// no exception: the errors are in result and the method decides

MethodArgumentNotValidException extends BindException, so an older handler for BindException still catches the @ModelAttribute case, which in older versions threw a plain BindException. Both expose getBindingResult() with the field errors, so one handler can format them the same way. If other parameters of the same method also carry constraints, method validation applies to the whole method and the @RequestBody failure is reported through HandlerMethodValidationException instead; check your version's documentation for the exact rule.

3@RequestParam With @Min: Built-in Method Validation

Before 6.1, a constraint on a @RequestParam was silently ignored unless the class had @Validated. Since 6.1, Spring MVC notices the constraint and validates the method's arguments itself.

Java
@RestController
class OrderController {
@GetMapping("/orders/page")
List<OrderDto> page(@RequestParam @Min(1) int page,
@RequestParam @Max(100) int size) { ... }
}
// GET /orders/page?page=0&size=500
// -> HandlerMethodValidationException, 400
// page: must be greater than or equal to 1
// size: must be less than or equal to 100

HandlerMethodValidationException collects the results per parameter. It offers getAllValidationResults() and a visitor style API that calls us back with the parameter's annotation, @RequestParam, @PathVariable, @RequestHeader and so on, so a handler can produce messages such as query parameter page must be at least 1. Notice the upgrade effect: an application that never validated these parameters now returns 400 for values it used to accept, which is correct but worth a release note.

4When the Controller Has @Validated

If the controller class is annotated with @Validated, the MethodValidationPostProcessor wraps it in a proxy, and the proxy validates constraints before the method runs. Its failure is the Jakarta exception ConstraintViolationException, which Spring MVC does not map to a status, so without a handler the client gets 500.

Java
@Validated // AOP method validation
@RestController
class LegacyController {
@GetMapping("/items")
List<Item> list(@RequestParam @Min(1) int page) { ... }
}
// GET /items?page=0 -> jakarta.validation.ConstraintViolationException -> 500 by default
Step throughWhich exception will a controller throw?
  1. Is @Validated on the controller class?
    YesAOP proxy: ConstraintViolationExceptionNoCheck the parameters
  2. Constraints directly on parameters?
    YesBuilt-in: HandlerMethodValidationExceptionNoCheck @Valid arguments
  3. @Valid @RequestBody or @ModelAttribute fails?
    YesMethodArgumentNotValidExceptionNoNo validation error

3 steps in order. Play them, or step through them one at a time.

Now two mechanisms can apply to the same controller: the built-in one and the AOP one, with different exceptions and different message formats. That is why Spring's reference documentation recommends not combining class-level @Validated with the built-in controller method validation. On 6.1 and later, the clean path is to remove @Validated from controllers and let the built-in support handle parameter constraints, keeping @Validated for service beans.

5One Handler for All of Them

A @ControllerAdvice extending ResponseEntityExceptionHandler already handles MethodArgumentNotValidException and HandlerMethodValidationException with 400 and a ProblemDetail body; we can override those methods to add field errors. ConstraintViolationException is not covered, so we map it ourselves for any remaining @Validated beans whose input comes from clients.

Java
@RestControllerAdvice
class ApiErrors extends ResponseEntityExceptionHandler {
@Override
protected ResponseEntity<Object> handleHandlerMethodValidationException(
HandlerMethodValidationException ex, HttpHeaders headers, HttpStatusCode status, WebRequest req) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(status, "Invalid request parameters");
pd.setProperty("errors", ex.getAllValidationResults().stream()
.flatMap(r -> r.getResolvableErrors().stream()
.map(e -> r.getMethodParameter().getParameterName() + ": " + e.getDefaultMessage()))
.toList());
return ResponseEntity.status(status).body(pd); // 400 {"errors": ["page: must be ..."]}
}
@ExceptionHandler(ConstraintViolationException.class)
ProblemDetail onViolation(ConstraintViolationException ex) {
return ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, ex.getMessage()); // 400 instead of 500
}
}

Newer versions add getParameterValidationResults() and may deprecate getAllValidationResults(), so check your version. The parameter name in the first handler requires compiling with -parameters, which Spring Boot's build plugins configure by default. With this advice in place, every validation failure reaches the client as a 400 in one format, whichever mechanism caught it.

6Follow-up questions

Why does ConstraintViolationException produce 500 by default?

Because it is not a Spring MVC exception. It can come from any validated bean, including a service validating its own internal calls, where a violation really is a server bug. Spring cannot know whether it was caused by client input, so it leaves the mapping to us.

Does built-in method validation need a dependency?

Yes, the same provider as all validation: spring-boot-starter-validation with Hibernate Validator. Without it, Spring MVC has no validator and constraints on parameters are ignored, just like @Valid on a body.

What about @PathVariable and @RequestHeader constraints?

They work the same way as @RequestParam since 6.1: a constraint directly on the parameter triggers built-in method validation and HandlerMethodValidationException. The visitor API on the exception tells which kind of parameter failed, so messages can say path variable or header.

7Conclusion

In this answer, we saw that @Valid @RequestBody and @Valid @ModelAttribute fail with MethodArgumentNotValidException, a subclass of BindException, that constraints directly on parameters such as @RequestParam @Min trigger built-in method validation and HandlerMethodValidationException since Spring 6.1, and that a class-level @Validated switches to AOP validation with ConstraintViolationException, a 500 unless handled. Spring recommends not combining the two, and one ResponseEntityExceptionHandler subclass can turn every case into a consistent 400.

What to say in the interviewAbout 80 seconds aloud

Open with

There are two mechanisms. For @Valid @RequestBody, the argument resolver binds the JSON, validates it and throws MethodArgumentNotValidException, which gives 400. For @Valid @ModelAttribute it is the same exception today; MethodArgumentNotValidException is a subclass of BindException, which is what older versions threw, so old handlers for BindException still catch it.

Then, if they want more

If I add a BindingResult parameter right after the argument, no exception is thrown and I handle the errors myself. For a @RequestParam with @Min, since Spring Framework 6.1 there is built-in method validation for controllers. A constraint directly on a parameter turns it on, and failures throw HandlerMethodValidationException, also 400, with results per parameter.

Before 6.1 those constraints were ignored unless the controller had @Validated. If the controller class does have @Validated, Spring's AOP method validation proxy runs instead and throws jakarta's ConstraintViolationException, which is a 500 by default because Spring MVC does not map it.

Spring's documentation recommends not mixing class-level @Validated with the built-in support, so on 6.1 and later I remove @Validated from controllers. Then I extend ResponseEntityExceptionHandler, override the two 400 handlers to add field errors, and map ConstraintViolationException to 400 for anything left over.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 6
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What exceptions are thrown when validation fails for a @RequestBody, a @ModelAttribute...": https://scrivio-interview-library.netlify.app/spring-boot/request-validation/6fc1ac4bec/