![](/img/trans.png)
[英]@AspectJ pointcut for all methods of a class with specific annotation
[英]@AspectJ pointcut for subclasses of a class with an annotation
我正在尋找一個切入點,該切入點與類中具有特定批注的子類的類中的方法執行相匹配。 出色的AspectJ備忘單幫助我創建了以下切入點:
within(@my.own.annotations.AnnotationToMatch *) && execution(* *(..))
這與帶有@AnnotationToMatch的類A的所有方法調用匹配,但與擴展了A的類B的方法匹配。我如何將兩者匹配?
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());
}
}
另一種更簡單的可能性是將注釋聲明為@Inherited-因此它也適用於子類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.