我加入了一个现有项目,该项目使用2个机制作为前端与spring mvc:
现在我发现了一个拦截器:
@Aspect
public class RequestMonitor {
@Autowired
private RequestMonitorService requestMonitorService;
@Before("execution(* org.springframework.web.servlet.mvc.Controller+.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse))"
+ "&& args(request,response)")
public void storeUserAccess(HttpServletRequest request, HttpServletResponse response) {
requestMonitorService.storeUserAccess(request);
}
}
谁收到来自org.springframework.web.servlet.mvc.Controller(机制A)的所有请求
我如何适应拦截带注释的所有其他控制器" @ Controller":org.springframework.stereotype.Controller(机制B)
答案 0 :(得分:3)
你有HandlerInterceptorAdapter课程。您可以扩展它并使用子类中的方法:
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception
public void postHandle(
HttpServletRequest request, HttpServletResponse response,
Object handler, ModelAndView modelAndView)
throws Exception
你需要注册你的拦截器,即:
<mvc:interceptors>
<bean class="my.fully.qualified.package.RequestInterceptor" />
</mvc:interceptors>