title: How can I lookup the method being called on a Handler from a Spring HandlerInterceptor?
body: <p>I have a Spring HandlerInterceptor intercepting the frontend URL's in my application (/app/*). I want to determine which action method in the Handler is about to be invoked from within the HandlerInterceptor. Is there a way to look that up, do I need to inject something into the interceptor that can look that up based on the requested path?</p>
  
  <p>The Interceptor is like this:</p>
  
  <pre><code>public class PageCacheInterceptor implements HandlerInterceptor {...}
  </code></pre>
  
  <p>It is mapped like this:</p>
  
  <pre><code>&lt;mvc:interceptors&gt;
      &lt;bean class="com.example.web.interceptors.PageCacheInterceptor" /&gt;
  &lt;/mvc:interceptors&gt;
  </code></pre>
  
  <p>Background (because I know you'll ask!). I am adding simple page caching to my app and want to use an annotation like @Cacheable on each suitable method in the controller. The interceptor can then determine whether to cache a response based on the action that created it.</p>
  
  <p>For example:</p>
  
  <pre><code>@RequestMapping(value = "", method = RequestMethod.GET)
  @Cacheable(events={Events.NEW_ORDER,Events.NEW_STAT})
  public String home(Model model) {...}
  </code></pre>
  
  <p>The events are the ones that cause the cache to be invalidated. For example /widget/list action would have it's cached response invalidated by a new widget being saved. </p>
  
  <p>Edit: I've upgraded to the latest Spring 3.1 M2, as <a href="http://blog.springsource.com/2011/06/13/spring-3-1-m2-spring-mvc-enhancements-2/" rel="noreferrer">this blog post</a> hinted at features I need, but it's not clear whether injecting these new classes or sub-classing them will be required. Has any one used them to retrieve the HandlerMethod in an interceptor?</p>