Description
Currently bean validation is applied to @ModelAttribute
and @RequestBody
arguments if they are also annotated with jakarta.validation.Valid
or Spring's @Validated
with validation groups. You can put constraint annotations directly on other arguments, but that requires @Validated
on the controller class with MethodValidationPostProcessor
applying method validation via AOP.
This is not intuitive and creates challenges for handling validation errors, e.g. to handle either ConstraintViolationException
or MethodArgumentNotValidException
. Also need to introspect method parameters to know if the failure is for a request header, path variable, or other, see #26219. It can lead to double validation, see #24913. It does not support reactive types, see #20781.
We need built-in method validation in web handling for a more integrated experience, default web exception handling of constraint violations to RFC 7807 responses.
This is an umbrella issue for the improvement:
- Spring MVC and WebFlux method validation support that also adapts
ConstraintViolation
s #29825 - Spring MVC and WebFlux handling of method validation errors #30644
- Method validation error handling by controller method parameter type #30813
- Update documentation for method validation improvements in spring-context, Spring MVC, and WebFlux #30643
- Update documentation on customizing validation errors with MessageSource #30653
- Support validating collection of objects on web controller method #16917