带有注释的类的子类的@AspectJ切入点 [英] @AspectJ pointcut for subclasses of a class with an annotation
本文介绍了带有注释的类的子类的@AspectJ切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个切入点,该切入点与类中具有特定注释的子类的类中的方法执行相匹配.出色的 AspectJ速查表帮助我创建了以下切入点:
I'm looking for a pointcut that matches method executions in classes that subclass a class with a specific annotation. The excellent AspectJ cheat sheet helped me to create the following pointcut:
within(@my.own.annotations.AnnotationToMatch *) && execution(* *(..))
这与带有@AnnotationToMatch的类A的所有方法调用匹配,但与扩展了A的类B的方法匹配.我如何将两者都匹配?
This matches all method calls of a class A that carries the @AnnotationToMatch, but not method of a class B that extends A. How can I match both?
推荐答案
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());
}
}
这篇关于带有注释的类的子类的@AspectJ切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文