I finally found a solution. I'm not sure the game is worth it, but it works :)
First add these things to your AbstractController:
public abstract class AbstractController {
@Autowired
protected MultipartHttpServletRequest request;
protected ModelMap model;
public void setModel(ModelMap model) {
this.model = model;
}
public ModelMap getModel() {
return model;
}
}
Then create an interceptor that implements org.springframework.web.servlet.HandlerInterceptor, like this one:
public class UserContextInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
if (handler instanceof AbstractController) {
AbstractController controller = (AbstractController) handler;
controller.setModel(new ModelMap());
}
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
if (handler instanceof AbstractController && modelAndView != null) {
AbstractController controller = (AbstractController) handler;
modelAndView.addAllObjects(controller.getModel());
}
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}
Finally, add these lines to your applicationContext.xml:
<mvc:interceptors>
<bean class="path.to.my.just.created.UserContextInterceptor" />
</mvc:interceptors>
, , , AbstractController.
! request, model :) , . :)
, .