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