I have two classes
public class ParentTestClass {
public void publicMethodOfParent() {
}
}
@Component
@MyAnnotation
public class ChildTestClass extends ParentTestClass {
public void publicMethodOfChild() {
}
}
With Spring AOP I need to wrap:
@MyAnnotation
if annotation is put on class level@MyAnnotation
if annotation is on the method level.Here is my pointcut
@Around("(@within(MyAnnotation) && execution(public * *(..))) || @annotation(MyAnnotation)")
public Object myWrapper(ProceedingJoinPoint invocation) throws Throwable {
// ...
}
This works for public methods of ChildTestClass
but ParentTestClass#publicMethodOfParent
is not wrapped when I make a call childTestClass.publicMethodOfParent()
How can I include parent methods?
Following pointcut expression will intercept the parent methods as well
From the documentation
@Pointcut("within(com.app..*) && execution(public * com.app..*.*(..))")
public void publicMethodsInApp() {
}
@Around("(publicMethodsInApp() && @target(MyAnnotation)) || "
+ "(publicMethodsInApp() && @annotation(MyAnnotation))")
public Object myWrapper(ProceedingJoinPoint invocation) throws Throwable {
//..
}
@target: Limits matching to join points (the execution of methods when using Spring AOP) where the class of the executing object has an annotation of the given type.