定义


@Before

声明一个方法为后置返回通知

参数


value

String value() default "";

可以为切入点表达式,也可以为使用了@PointCut被声明为切入点的方法。

pointcut

String pointcut() default "";

value,在两者间选择一个使用。

returning

String returning() default "";

后置返回通知中用于获取返回值的参数名。

示例


@Aspect  
@Component
@Slf4j
public class LogAspect {
	@PointCut("@annotation(com.example.annotation.Log)")
	public void logAnnotation() { }
	
	@AfterReturning(pointcut = "logAnnotation()", returning = "returnValue")
	public void logAfterReturning(JoinPoint joinPoint,Object returnValue) {  
		MethodSignature signature = (MethodSignature) joinPoint.getSignature();  
		Method method = signature.getMethod();
		log.info(“after method:{} successed with:{}”, method.getName(), returnValue);
	}
}
Link to original