我正在寻找一个切入点,该切入点匹配使用特定注释对类进行子类化的类中的方法执行。优秀的AspectJ cheat sheet帮助我创建了以下切入点:
within(@my.own.annotations.AnnotationToMatch *) && execution(* *(..))
这匹配带有@AnnotationToMatch的A类的所有方法调用,但不匹配扩展A的B类方法。如何匹配两者?
答案 0 :(得分:3)
public aspect AnnotatedParentPointcutAspect {
//introducing empty marker interface
declare parents : (@MyAnnotation *) implements TrackedParentMarker;
public pointcut p1() : execution(* TrackedParentMarker+.*(..));
before(): p1(){
System.out.println("Crosscutted method: "
+thisJoinPointStaticPart.getSignature().getDeclaringTypeName()
+"."
+thisJoinPointStaticPart.getSignature().getName());
}
}
答案 1 :(得分:3)
另一个更简单的可能性是将注释声明为@Inherited - 因此它也适用于子类。