title: Spring validation ConstraintViolationException cannot be caught using ControllerAdvice
body: <p>I am building APIs with spring rest and trying to validate the input parameters, like this:</p>
  
  <pre><code>@RequestMapping("/myUrl")
  @RestController
  @Validated
  public class MyController {
  
    @ResponseStatus(HttpStatus.OK)
    @RequestMapping(value = "getSomething", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
    public myResponse getMarketResult(
    @RequestParam @NotNull @NotBlank @NotEmpty String inputParam) {
      //...my implementation
    }
  }
  </code></pre>
  
  <p>The validation does work in all these scenarios (null, blanks, empty).
  MissingServletRequestParameterException is thrown for null, ConstraintViolationException is thrown for blanks/empty.</p>
  
  <p>Controller advice:</p>
  
  <pre><code>@ControllerAdvice
  public class ControllerValidationHandler extends ResponseEntityExceptionHandler {
  
    @ExceptionHandler(NestedServletException.class)
    public ResponseEntity&lt;Object&gt; processValidationError(NestedServletException ex, HttpStatus status, WebRequest request) {
      // my implementation
    }
  
    @ExceptionHandler(ConstraintViolationException.class)
    public ResponseEntity&lt;Object&gt; processValidationError(ConstraintViolationException ex, HttpStatus status, WebRequest request) {
      // my implementation
    }
  
    @Override
    protected ResponseEntity&lt;Object&gt; handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
      // my implementation
    }
  
    @ExceptionHandler(Exception.class)
    public ResponseEntity&lt;Object&gt; handleExpception(HttpServletRequest req, Exception ex, WebRequest request) {
      // my implementation
    }
  </code></pre>
  
  <p>However I observe:</p>
  
  <ol>
  <li><p>ConstraintViolationException is thrown as the cause of org.springframework.web.util.NestedServletException.</p></li>
  <li><p>ControllerAdvice is unable to catch ConstraintViolationException and NestedServletException (But MissingServletRequestParameterException works), it's now returning a html (instead of json).</p></li>
  </ol>
  
  <p>The 2 exceptions are not processed by 'handleException' of ResponseEntityExceptionHandler as well.</p>
  
  <p>How do I solve 1 and 2? I'm using Spring version 4.3.1</p>
  
  <p>Edit 1:
  One more example, if I have a parameter like this:</p>
  
  <pre><code>@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @NotNull LocalDate localDate
  </code></pre>
  
  <p>Expcetion is thrown as mentioned in (1) when the request is empty (eg '/myURL/getSomething?localDate='</p>