The new MethodValidationException
introduced as part of #29825 needs to have default handling in Spring MVC and WebFlux, including RFC 7807 support, similar to the handling of BindException
but reflecting errors for multiple method parameters / or return value, represented with ParameterValidationResult
and ParameterErrors
.
Comment From: rstoyanchev
There is now a new HandlerMethodValidationException
, similar to the MethodValidationException
raised when method validation is applied via AOP (to any Spring component), but extending from ResponseStatusException
and thrown from the built-in method validation support for @RequestMapping
methods.
The new exception is handled in ResponseEntityExceptionHandler
and in DefaultHandlerExceptionResolver
as e 400 error if is for method arguments, and as a 500 error if it is for a return value. MethodValidationException
(possibly from an underlying service) is handled as a 500 error.
By default for RFC 7807, the detail of ProblemDetail
is just a short message "Validation failure". You can customize that with a MessageSource
as described in the reference documentation where the {0}
argument for HandlerMethodValidationException
is the list of all errors. For more control, handle this exception directly and provide it with a Visitor
to handle controller method parameters individually.
Comment From: ctapobep
From the documentation it's not clear - does this mean that the old MethodArgumentNotValidException
isn't going to be used by Spring MVC anymore? We should always expect HandlerMethodValidationException
on the API level from now on?