title: Spring-Data-Rest Validator
body: <p>I have been trying to add spring validators to a spring-data-rest project.</p>
  
  <p>I followed along and setup the "getting started" application via this link: <a href="http://spring.io/guides/gs/accessing-data-rest/" rel="noreferrer">http://spring.io/guides/gs/accessing-data-rest/</a></p>
  
  <p>...and now I am trying to add a custom PeopleValidator by following the documents here:
  <a href="http://docs.spring.io/spring-data/rest/docs/2.1.0.RELEASE/reference/html/validation-chapter.html" rel="noreferrer">http://docs.spring.io/spring-data/rest/docs/2.1.0.RELEASE/reference/html/validation-chapter.html</a></p>
  
  <p>My custom PeopleValidator looks like</p>
  
  <pre><code>package hello;
  
  import org.springframework.validation.Errors;
  import org.springframework.validation.Validator;
  
  public class PeopleValidator implements Validator {
      @Override
      public boolean supports(Class&lt;?&gt; clazz) {
          return true;
      }
  
      @Override
      public void validate(Object target, Errors errors) {
          errors.reject("DIE");
      }
  }
  </code></pre>
  
  <p>...and my Application.java class now looks like this</p>
  
  <pre><code>package hello;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Import;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
  
  @Configuration
  @EnableJpaRepositories
  @Import(RepositoryRestMvcConfiguration.class)
  @EnableAutoConfiguration
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
      @Bean
      public PeopleValidator beforeCreatePeopleValidator() {
          return new PeopleValidator();
      }
  }
  </code></pre>
  
  <p>I would expect that POSTing to the <code>http://localhost:8080/people</code> URL would result in an error of some kind since the PeopleValidator is rejecting everything. However, no error is thrown, and the validator is never called.</p>
  
  <p>I have also tried manually setting up the validator as shown in section 5.1 of the spring-data-rest documentation.</p>
  
  <p>What am I missing?</p>