对于用例,我们需要创建自定义注释,该注释将记录使用此注释注释的方法的返回值。 对于输入arg它很简单,但如何创建返回值?
答案 0 :(得分:0)
使用@Around
并记录结果:
@Aspect
public class YourAspect {
@Around("@annotation(YourAnnotation) && execution(* *(..))")
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
Object returnObject = null;
try {
returnObject = joinPoint.proceed();
} catch (Throwable throwable) {
// You may want to log this
throw throwable;
}
// log returnObject here...
return returnObject;
}
}