I use a HandlerInterceptorAdapter for that. I have a class like this:
Code:
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class ToolInjectorInterceptor extends HandlerInterceptorAdapter {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
if (modelAndView != null) {
modelAndView.addObject("stringTool", new StringTool());
}
}
}
and configure its usage in my servlet context like this:
Code:
<!-- default handler mappings to process @RequestMapping Annotations - needed as we customize -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" >
<property name="interceptors">
<list>
<ref bean="openSessionInViewInterceptor"/>
<bean class="ToolInjectorInterceptor" />
</list>
</property>
</bean>
That way I can enrich my model with whatever I need in all request processing and the interceptor also has access to the request.