user496949
user496949

Reputation: 86145

How to get the caller method information from Around advise

ThisJoinPoint can only get the current method information, anyway to get the caller method information?

Upvotes: 3

Views: 9535

Answers (2)

vootla561
vootla561

Reputation: 11

@Aspect
public class LoggingAspect {

    @Before(value = "execution(public * findAll())")
    public void beforeAdvice(JoinPoint pp){
        System.out.println("before advice called ....get calling method Signature"+pp.getSignature());
        System.out.println("before advice called ....get calling method name"+pp.getSignature().getName());
    }

}

Upvotes: 0

janhink
janhink

Reputation: 5023

You can try the special variable thisEnclosingJoinPointStaticPart which holds the static part of the enclosing JoinPoint.

Mentioned here (example) and here (docs)

Or if using annotation-based AspectJ, pass following to the advice method's parameters, e.g.:

@Before("call( /* your pointcut definition */ )")
public void myCall(JoinPoint.EnclosingStaticPart thisEnclosingJoinPointStaticPart)
{
     // ...
}

Mentioned here

Upvotes: 4

Related Questions