title: Capturing Hibernate Validator message text in Spring MVC
body: <p>I am working on a REST api using Spring-MVC and json. I running my automatic tests using Jetty and an in-memory database. I want to test that posting an invalid domain object gives me the error message from the <code>@NotEmpty</code> annotation. But all I get is the default Jetty 400 Bad Request page.</p>
  
  <p>I have a domain class with some validation:</p>
  
  <pre><code>@Entity
  public class Company {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @NotEmpty(message = "Name is a required field")
      private String name;
  
      /* getters, setters */
  }
  </code></pre>
  
  <p>Here's the controller</p>
  
  <pre><code>@Controller
  public class CompanyController {
      @RequestMapping(value = "/company", 
          method = RequestMethod.POST, 
          consumes = "application/json")
      public void createCompany(
          @Valid @RequestBody final Company company,
          final HttpServletResponse response) {
  
          //persist company
          response.setStatus(HttpServletResponse.SC_CREATED);
          response.setHeader("location", "/company/" + company.getId());
      }
  }
  </code></pre>
  
  <p>How can I get the value <code>"Name is a required field"</code> returned as part of the response?</p>