I need to execute some common code for several ‘around’ advices. So, I have moved the common code to a function. But the problem I have is that, proceed() does not work inside this common function. Please see code below.
aspect MyAspect {
pointcut myPointCut() : execution(* com.test.MyTestInterface.*(..));
Object around() : myPointCut() {
Object retVal = null;
try {
ProceedingJoinPoint pjp = (ProceedingJoinPoint) thisJoinPoint;
myfunction(pjp);
} catch (Throwable e) {
e.printStackTrace();
}
return retVal;
}
public void myfunction(ProceedingJoinPoint pjp) {
System.out.println("Inside myfunction()" + pjp.getSignature());
pjp.proceed();
}
}
Casting thisJoinPoint to ProceedingJoinPoint doesn’t work. “Inside myfunction()” is printed, but the next statement does not execute the method that was intercepted by the pointcut.
Is there any way to achieve this?
I didn’t get it to work with the traditional syntax but I think I might have a solution with the @AspectJ Syntax: