1

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
simon
  • 12,666
  • 26
  • 78
  • 113

2 Answers2

4

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
0

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

Kannan Ekanath
  • 16,759
  • 22
  • 75
  • 101