使用Controller的@Around建议不起作用

时间:2015-11-18 07:28:35

标签: java spring-security spring-boot spring-aop

我试图在Spring启动应用程序中使用AOP记录控制器方法(使用Spring安全性)并且无法将其解决。它没有返回任何异常,并且在添加与方面相关的代码后无法检测到处理程序方法:

控制器方法:

@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]

如果Aspect相关代码已注释,则索引页面无任何问题返回

有什么见解?

1 个答案:

答案 0 :(得分:0)

控制器已经被spring mvc代理,可能是没有安装around建议。我在几年前遇到了同样的问题,很快就使用了日志过滤器解决了它。您还可以定义HandlerInterceptor

相关问题