title: Spring Boot Validation with ControllerAdvice Not Behaving Deterministically
body: <p>I have the following setup</p>
  
  <pre><code>@ControllerAdvice
  public class AppControllerAdvice extends ResponseEntityExceptionHandler {
  
      @ExceptionHandler({UserInputValidationException.class})
      public ResponseEntity&lt;UserInputValidationResponseBody&gt; handleBadInputException(UserInputValidationException ex, WebRequest request) {
          return new ResponseEntity&lt;&gt;(
                  new UserInputValidationResponseBody().setFieldErrors(ex.getFieldErrors()),
                  HttpStatus.BAD_REQUEST
          );
      }
  
  }
  </code></pre>
  
  <p>This is roughly the <code>@RestController</code> that throws well formatted validation exceptions</p>
  
  <pre><code>@RestController
  @RequestMapping("api")
  public class MyController {
  
  
  /**
  per the answer, BindingResult must immediately follow the @RequestBody or the item being found
  */
      @PostMapping
      public ResponseEntity&lt;?&gt; foo(@Valid @RequestBody FormPOJO formBody, Principal principal, BindingResult bindingResult) {
          // if bindingResult has errors, throw a UserInputValidationException
      }
  }
  </code></pre>
  
  <p>And POJOs that I want to bind have JSR-303 validation annotations on them, Spring correctly validate them at Bind time during request parameter binding</p>
  
  <p>However ... while I got this setup to work for a while - then Spring randomly started to bypass the <code>@RestController</code> and <code>@ControllerAdvice</code></p>
  
  <p>It appears that now I am receiving <code>org.springframework.web.bind.MethodArgumentNotValidException</code> ... i.e. the request is getting short circuited </p>
  
  <p>I am running Spring Boot 1.5.4.RELEASE ... </p>
  
  <p><strong>EDIT</strong> following suggestion from <a href="https://stackoverflow.com/questions/33663801/how-do-i-customize-default-error-message-from-spring-valid-validation">another thread</a>, I added</p>
  
  <pre><code>@Order(Ordered.HIGHEST_PRECEDENCE)
  </code></pre>
  
  <p>to the controller advice ... it only served to make matters worse. now there is absolutely no validation errors - the client only receives a blank message (which was the symptom of the problem for a while before the current issue surfaced without any code changes)</p>