正如Nicholas指出的那样,这在AspectJ中是不可能的。这是无法实现的更多证据(摘自http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations-
pointcuts-and-
advice.html注释继承和切入点匹配部分):
根据Java
5规范,不继承非类型注释,并且只有具有@Inherited元注释的类型注释才被继承。对c2.aMethod的调用(在您的示例中为b.method())不匹配,因为修饰符(可见性修饰符,注释和throws子句)的连接点匹配基于连接点的主题(方法实际上被调用)。
经历过同样的问题后,我编写了一个小的方法/库,使您可以为此类方法编写切入点。这是您的示例的工作方式:
myAnnotationIsExecuted(): execution(public * *.*(..)) && if(implementsAnnotation("@MyAnnotation()", thisJoinPoint));要么
myAnnotationIsExecuted(): execution(public * A+.*(..)) && if(implementsAnnotation("@MyAnnotation()", thisJoinPoint));该方法
implementsAnnotation(String,JoinPoint)来自库;一种基本方法,用于检查实现的方法是否包含指定的批注。
可以在此处找到有关方法/库的更多信息。



