title: Register Spring HandlerInterceptor Without WebMvcConfigurationSupport
body: <p>I'm trying to register an instance of <code>HandlerInterceptor</code> in Spring using Java Config <em>without</em> extending <code>WebMvcConfigurationSupport</code>. I'm creating a library with an annotation that, when added to a <code>@Configuration</code> class, registers an interceptor that handles a security annotation.</p>
  
  <p>I had an implementation using <code>WebMvcConfigurationSupport#addInterceptors</code>, but that conflicted with other automatic workings in spring, and overrode some of the application's own logic. It also seems incredibly heavy for something that should be simple. I'm now trying:</p>
  
  <pre><code>@Configuration
  public class AnnotationSecurityConfiguration {
  
      @Autowired private RequestMappingHandlerMapping requestMappingHandlerMapping;
  
      @PostConstruct
      public void attachInterceptors() {
          requestMappingHandlerMapping.setInterceptors(new Object[] {
                  new SecurityAnnotationHandlerInterceptor()
          });
      }
  
  }
  </code></pre>
  
  <p>However, it appears that the interceptor gets registered with a completely different instance of <code>RequestMappingHandlerMapping</code> than the one the application actually uses for web requests. Additionally, when implemeted as a <code>BeanFactoryPostProcessor</code>, I get a <code>NullPointerException</code> in <code>HealthMvcEndpoint</code> when I try <code>beanFactory.getBean(RequestMappingHandlerMapping.class)</code></p>