定义
后置通知
参数
JoinPoint
在需要连接点(方法)的信息时,可以为通知添加一个JoinPoint类型的参数来获取。
参数位置
在Spring中,建议将
JoinPoint作为第一个参数。
@Aspect
@Component
@Slf4j
public class LogAspect {
@PointCut("@annotation(com.example.annotation.Log)")
public void logAnnotation() { }
@After("logAnnotation()")
public void logAfter(JoinPoint joinPoint) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
log.info(“after method:{}”, method.getName());
}
}