How would one create a pointcut that matches methods that are annotated with an annotation or whose interface method is annotated with an annotation?
public interface IService {
@SomeAnnotation
public void someMethod() { ... }
}
public class Service implements IService {
public void someMethod() { ... }
}
I'm using Spring AOP for AspectJ autoproxying. However, if I define a pointcut like
execution(public * *(..)) && @annotation(SomeAnnotation)
the advice is not applied on the someMethod method on Service.
What would be the correct pointcut to match that method, 开发者_运维知识库only using the fact that the interface method has an annotation on it? Is it possible?
If I put the annotation on the Service someMethod method, the above pointcut works, but in my case, this is not a good solution, as the annotation is part of the contract and must therefor be part of the interface, not the implementation.
According to the Java 5 specification, non-type annotations are not inherited, and annotations on types are only inherited if they have the @Inherited meta-annotation.
http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations-pointcuts-and-advice.html#annotation-inheritance-and-pointcut-matching
精彩评论