tags:

views:

63

answers:

2

I have a web application developed with Spring 2.5. The application has numerous controllers, containing GET and POST request methods, which are marked with RequestMapping annotations, like this:

@RequestMapping(method = RequestMethod.GET)

I would want to execute some code before each such request, without modifying the existing controllers. How can I accomplish this, if possible?

+3  A: 

You want to use a HandlerInterceptor. These "crosscut" your controllers. See this Spring docs for more info.

skaffman
A: 

I may be wrong here but weren't HttpFilters (that can intercept requests) designed for the same thing?

Calm Storm
Yes, but they're not very Spring-friendly
skaffman