春季AOP建议不要建议休息控制器方法

时间:2018-11-03 04:10:45

标签: spring-mvc aspectj spring-aop

我试图在基于Spring和Spring MVC的应用程序中审核RestController中的所有请求。以下是我的应用程序的配置。

我在配置类中启用了@EnableAspectJAutoProxy(proxyTargetClass = true)并按如下方式创建了一个类

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Loggable {

}

@Aspect
@Component
public class RequestLogAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(RequestLogAspect.class);

@Around("@annotation(com.buckzy.account.web.logger.Loggable)")
public Object log(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes())
            .getRequest();

    Object value;

    try {
        value = proceedingJoinPoint.proceed();
    } catch (Throwable throwable) {
        throw throwable;
    } finally {
        LOGGER.info(
                "{} {} from {}",
                request.getMethod(),
                request.getRequestURI(),
                request.getRemoteAddr(),
                request.getHeader("user-id"));
    }

    return value;
  }
}

但是每当我调用控制器方法时,advis都不会被调用。我在这里缺少什么?如何调试此问题?

0 个答案:

没有答案
相关问题