How can I find a method called in a handler from Spring HandlerInterceptor?

I have a Spring HandlerInterceptor intercepting the interface URL in my application (/ app / *). I want to determine which action method in the handler should be called from the HandlerInterceptor. Is there any way to look at this, do I need to inject something into the interceptor, which might look like this based on the requested path?

The interceptor is as follows:

public class PageCacheInterceptor implements HandlerInterceptor {...}

It is displayed as follows:

<mvc:interceptors>
    <bean class="com.example.web.interceptors.PageCacheInterceptor" />
</mvc:interceptors>

Background (because I know what you ask!). I am adding simple page caching to my application and want to use annotation like @Cacheable for every suitable method in the controller. The interceptor can then determine if the response should be cached based on the action that created it.

For instance:

@RequestMapping(value = "", method = RequestMethod.GET)
@Cacheable(events={Events.NEW_ORDER,Events.NEW_STAT})
public String home(Model model) {...}

- , . , /widget/list , .

: Spring 3.1 M2, , , , . - HandlerMethod ?

+5
2

, :

1) Spring 3.1

2) RTFM ()

, HandlerInterceptor Object to HandlerMethod , ..

3) HandlerMethod Interceptor.

:

    HandlerMethod method = (HandlerMethod) handler;
    Cacheable methodAnnotation = method.getMethodAnnotation(Cacheable.class);
    if (methodAnnotation != null) {
        System.out.println("cacheable request");
    }
+7
@Override 
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 
System.out.println("Pre-handle"); 
HandlerMethod hm=(HandlerMethod)handler; 
Method method=hm.getMethod(); if(method.getDeclaringClass().isAnnotationPresent(Controller.class)){
 if(method.isAnnotationPresent(ApplicationAudit.class))
{ 
System.out.println(method.getAnnotation(ApplicationAudit.class).value()); 
request.setAttribute("STARTTIME",System.currentTimemillis());
 }
} 
return true; 
} 

, , http://www.myjavarecipes.com/spring-profilingaudit-using-mvc-filters/

0

All Articles