I am confused by writing a pointcut that matches all executions of a method. I tried the pointcut that should match all method-executions of class Alpha
:
execution(* Alpha.*(..))
with the following class-hierachy
public class Alpha {
public void alphaMethod() {...}
}
public class Beta extends Alpha {
public void betaMethod() {
alphaMethod();
}
}
If the Main-program calls alphaMethod
on an Beta
-instance my advice is called like expected but the Main-program calls betaMethod
that also calls alphaMethod
inside my advice is not called and I don't understand why.
Aspect-Definition:
@Aspect
public class MyAspect {
@Before(value = "execution(* Alpha.*(..))", argNames="joinPoint")
public void myAdvice(JoinPoint joinPoint) {
System.out.println("BEFORE: " + joinPoint.getSignature());
}
}
Main-method:
Beta beta = ...;
beta.alphaMethod(); //advice is called
beta.betaMethod(); //advice is NOT called.