title: Spring HandlerInterceptor: how to access class annotations?
body: <p>I registered my interceptor with the following code</p>
  
  <pre><code>@EnableWebMvc
  public class WebMvcConfig extends WebMvcConfigurerAdapter {
   ...
   @Override
   public void addInterceptors(InterceptorRegistry registry) {
      registry.addInterceptor( myInterceptor() );
   }
   ...
  }
  </code></pre>
  
  <p>Here the interceptor definition</p>
  
  <pre><code>public class MyInterceptorimplements HandlerInterceptor {
  
  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
  
      // Check to see if the handling controller is annotated
      for (Annotation annotation : Arrays.asList(handler.getClass().getDeclaredAnnotations())){
          if (annotation instanceof MyAnnotation){
              ... do something
  </code></pre>
  
  <p>However the handler.getClass().getDeclaredAnnotations() is not returning the class level annotations of the Controller intercepted. </p>
  
  <p>I can only get the method level annotations which is not what I want in this case.</p>
  
  <p>The same interceptor works fine with xml configuration (using Spring 3):</p>
  
  <pre><code>&lt;bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"&gt;
      &lt;property name="interceptors"&gt;
          &lt;list&gt;
              &lt;ref bean="myInterceptor"/&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Is there a way to have class level information in Spring 4?</p>
  
  <p>According to 
  <a href="https://stackoverflow.com/questions/17575623/in-a-spring-mvc-interceptor-how-can-i-access-to-the-handler-controller-method">In a Spring-mvc interceptor, how can I access to the handler controller method?</a>
  "HandlerInterceptors will only provide you access to the HandlerMethod" using the configuration above. But what is the alternative configuration to get class level information?</p>