title: How to handle MethodArgumentNotValidException
body: <p>I would like to handle exception thrown by validator.</p>
  
  <p>I've made exception handler with ControllerAdvice annotation. It handles other exceptions but not MethodArgumentNotValidException.</p>
  
  <p>Exception handler</p>
  
  <pre><code>@ControllerAdvice
  public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
  
      @ExceptionHandler(value
          = {ResourceNotFoundException.class, EntityNotFoundException.class})
      protected ResponseEntity&lt;Object&gt; handleNotFound(
          RuntimeException ex, WebRequest request) {
  
      APIException apiException = new APIException(HttpStatus.NOT_FOUND,
              ex.getMessage(), request);
  
      return handleExceptionInternal(ex, apiException,
              new HttpHeaders(), apiException.getStatus(), request);
      }
  
      @Override
      protected ResponseEntity&lt;Object&gt; handleMethodArgumentNotValid
              (MethodArgumentNotValidException ex,
                   HttpHeaders headers, HttpStatus status, WebRequest request)     {
          APIException apiException = new APIException(HttpStatus.BAD_REQUEST,
              ex.getMessage(), request);
  
          return handleExceptionInternal(ex, apiException,
              new HttpHeaders(), apiException.getStatus(), request);
      }
  }
  </code></pre>
  
  <p>Validated class (without getters/setters etc.)</p>
  
  <pre><code>public class ClassQuery {
      @Min(1)
      private Integer minYear;
      @Min(1)
      private Integer year;
      @Min(1)
      private Integer maxYear;
      private String name;
      private String profile;
  }
  </code></pre>
  
  <p>Rest api controller</p>
  
  <pre><code>@GetMapping
  public Page&lt;Class&gt; getClasses(@Valid ClassQuery classQuery, Pageable pageable) {
      return classService.getClasses(classQuery, pageable);
  }
  </code></pre>
  
  <p>Api Exception (without getters/setters etc.)</p>
  
  <pre><code>public class APIException {
      private Date timestamp;
      private HttpStatus status;
      private String message;
      private String path;
  
      public APIExceptionMessage(HttpStatus status, String message, WebRequest request) {
              this();
              this.status = status;
              this.message = message;
              this.path = getRequestURI(request);
      }
  }
  </code></pre>
  
  <p>Currently I'm getting an empty response with BAD_REQUEST http status from validator while other exceptions are handled correctly. I've also tried no extending ResponseEntityExceptionHandler and handle it with @ExceptionHandler but it was ignoring my response body, in response it gave default error message. I'm not getting any error.</p>