我有这样的基于方面的日志记录:
@Pointcut("@annotation(Loggable)")
public void loggableAnnotation() {}
@Around("loggableAnnotation()")
public Object simpleProcess(ProceedingJoinPoint joinPoint) throws Throwable {
return this.processWithBody(joinPoint, null);
}
@Around("loggableAnnotation() && args(@org.springframework.web.bind.annotation.RequestBody body,..)")
public Object processWithBody(ProceedingJoinPoint joinPoint, Object body) throws Throwable {
// do things
}
并且当我用@RequestBody
执行请求时,它工作正常,建议processWithBody()
被触发。但是,当我执行没有@RequestBody
(仅@PathVariable
和@RequestParam
)的请求时,不会触发simpleProcess()
,而是在processWithBody()
中接收路径变量值作为body
参数。
为什么会发生,我如何以不同的方式处理两种类型的请求(如果可能,在相同的建议中?)>
我有这样的基于方面的日志记录:@Pointcut(“ @ annotation(Loggable)”)public void loggableAnnotation(){} @Around(“ loggableAnnotation()”)public Object simpleProcess(ProceedingJoinPoint joinPoint)...
您正在制造三个基本错误:
您正在尝试从args()
内部匹配参数自变量注解,但没有任何效果,这就是processWithBody(..)
匹配不需要的参数并将其绑定到body
的原因。应该将其传输到execution()
切入点。