我正在尝试在 Spring boot 应用程序(具有 Spring 安全性)中使用 AOP 来记录 Controller 方法,但无法成功。添加方面相关代码后,它不会返回任何异常,并且处理程序方法无法检测到:
Controller 方法:
@RequestMapping(value="/index", method = RequestMethod.GET)
public ModelAndView welcome() {
ModelAndView modelView = new ModelAndView();
modelView.setViewName("index");
return modelView;
}
方面:
@Pointcut("within(@org.springframework.web.bind.annotation.RequestMapping *)")
public void requestMapping() {}
@Around("execution(* com.hms.controllers.HomeController.*(..)) && @annotation(requestMapping)")
public void aroundControllerMethod(ProceedingJoinPoint joinPoint, RequestMapping requestMapping) {
System.out.println("Testing aroundController: " + joinPoint.getSignature().getName());
}
失败并显示以下日志:
2015-11-18 12:57:41.310 DEBUG 6180 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /index
2015-11-18 12:57:41.310 DEBUG 6180 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/index]
如果与方面相关的代码被注释,索引页面返回没有任何问题
有什么见解吗?
最佳答案
Controller 已由 spring mvc 代理,并且可能未安装周围建议。几年前我遇到了同样的问题,并使用日志过滤器很快解决了它。您还可以定义一个HandlerInterceptor
关于java - @Around Controller 的建议不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33774102/