I'm getting na exception on the following method:
@Transactional
@RequestMapping(method=RequestMethod.PUT)
public @ResponseBody Account create(@Valid @RequestBody CreateAccountRequest request, BindingResult bindingResult)
{ ...
}
Throws the following exception:
java.lang.IllegalStateException: An Errors/BindingResult argument is expected to be immediately after the model attribute argument in the controller method signature: public com.mangofactory.concorde.domain.Account com.mangofactory.concorde.api.AccountService.create(com.mangofactory.concorde.api.rpc.CreateAccountRequest,org.springframework.validation.BindingResult)
According to the documentation, I'm required to add a BindingResult
as the second parameter. However, I've done that.
It's even present in the exception.
What have I missed?
Turns out that the way to solve this was to remove the BindingResult
property completely.
The signature that worked was:
public @ResponseBody CreateAccountResponse create(@Valid @RequestBody CreateAccountRequest request)
This was as tipped by point #3 on this blog post.
BindingResult is supported only after @ModelAttribute arguments. The combination of @Valid and @RequestBody raises a MethodArgumentNotValidException, which by default is translated to a 400 error code. This is documented in the reference documentation and on @RequestMapping itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With