我试图在基于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都不会被调用。我在这里缺少什么?如何调试此问题?