带有注释的类的子类的@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屋!
查看全文