I have a custom annotation with which I've annotated a method in my Controller alongside a @ReqestMapping.
The goal is to use the values set in the custom annotation from a HandlerInterceptor to perform a task.
I have the interceptor (HandlerInterceptorAdaptor) mapped and it executes. If I set a breakpoint in my concrete Interceptor I can inspect the HttpServletRequest, HttpServletResponse, and handler Objects. However, I cannot see how to 1, obtain the method which the request is trying to access 2, obtain the Annotations on that method and 3, of course, obtain the values set by the annotation.
Can anyone point me to good documentation for this?
Please and Thank You.
The @Controller annotation indicates that a particular class serves the role of a controller. Spring Controller annotation is typically used in combination with annotated handler methods based on the @RequestMapping annotation.
Spring Handler Interceptor The HandlerInterceptor contains three main methods: prehandle() – called before the execution of the actual handler. postHandle() – called after the handler is executed. afterCompletion() – called after the complete request is finished and the view is generated.
Spring Interceptor are used to intercept client requests and process them. Sometimes we want to intercept the HTTP Request and do some processing before handing it over to the controller handler methods. That's where Spring MVC Interceptor come handy.
AOP will be a good fit for you. You should be able to write an advice which performs your task, with a joinpoint definition capturing the context of the called controller - Any custom annotations that you have, along with the passed parameters.
in Spring 3.1 we've introduced a HandlerMethod abstraction to represent that specific controller method that will handle the request. There is HandlerMapping and a HandlerAdapter specifically for that. You can read about this in more detail in my blogpost following the M2 release.
https://spring.io/blog/2011/06/13/spring-3-1-m2-spring-mvc-enhancements/
Spring 3.1 is not released GA yet. Of course, it is available as a milestone release and also as a nightly snapshot. Either way, it is something you should take into consideration and hence worth mentioning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With