I am using a Default AnnotationMethodHandlerAdapter which I believe should enable support for @ExceptionHandler. Unluckily, a ServletRequestBindingException is thrown if a c
This issue is fixed in Spring 3.2. You can create a global exception handler class with the @ControllerAdvice annotation. Then in that class add an @ExceptionHandler method to handle the ServletRequestBindingException and return a custom response body. Example:
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(ServletRequestBindingException.class)
public ResponseEntity handleServletRequestBindingException(ServletRequestBindingException ex) {
return new ResponseEntity("MISSING REQUIRED HEADER",HttpStatus.PRECONDITION_REQUIRED);
}
}
For more information check the spring mvc docs: 17.11 Handling exceptions