title: How to add Custom Interceptor in Spring data rest (spring-data-rest-webmvc 2.3.0)
body: <p>I am working on the spring data rest services &amp; facing some issue in the custom interceptors. Earlier I used spring-data-rest-webmvc 2.2.0 &amp; added interceptor in following way.</p>
  
  <pre><code>public RequestMappingHandlerMapping repositoryExporterHandlerMapping() {
          RequestMappingHandlerMapping mapping = super
                  .repositoryExporterHandlerMapping();
  
          mapping.setInterceptors(new Object[] { new MyInterceptor() });
  
          return mapping;
  }
  </code></pre>
  
  <p>It worked perfectly fine for me. But when i upgraded to spring-data-rest-webmvc 2.3.0 version, I noticed that handlerMapping is hidden behind DelegatingHandlerMapping. Hence I tried to add interceptor in following way.</p>
  
  <p>In one of my config class I have extended RepositoryRestMvcConfiguration class &amp; override its method.</p>
  
  <pre><code>public class AppConfig extends RepositoryRestMvcConfiguration {
  @Autowired ApplicationContext applicationContext;
  
  @Override
  public DelegatingHandlerMapping restHandlerMapping()
      {
          RepositoryRestHandlerMapping repositoryMapping = new RepositoryRestHandlerMapping(super.resourceMappings(), super.config());
          repositoryMapping.setInterceptors(new Object[] { new MyInterceptor()});
          repositoryMapping.setJpaHelper(super.jpaHelper());
          repositoryMapping.setApplicationContext(applicationContext);
          repositoryMapping.afterPropertiesSet();
  
          BasePathAwareHandlerMapping basePathMapping = new BasePathAwareHandlerMapping(super.config());
          basePathMapping.setApplicationContext(applicationContext);
          basePathMapping.afterPropertiesSet();
          List&lt;HandlerMapping&gt; mappings = new ArrayList&lt;HandlerMapping&gt;();
          mappings.add(basePathMapping);
          mappings.add(repositoryMapping);
  
          return new DelegatingHandlerMapping(mappings);
  
      }
  }
  </code></pre>
  
  <p>But after adding this some of my repository operations (findAll() operation on repository) start failing. If I removed this interceptors those operations worked fine. (In this interceptor I am just authenticate the user.)
  Hence I am unable to understand problem here. Am I adding the interceptor in wrong way? Is there any other way to add the interceptor? </p>