how to write Get() pointcut to retrive the attributes that have been used in the program in AspectJ

StackOverflow https://stackoverflow.com/questions/21794690

  •  12-10-2022
  •  | 
  •  

Question

I have written the following pointcut but it is giving the run time error (Exception in thread "main" java.lang.StackOverflowError)

pointcut traceAttribs():(get(* *));

Was it helpful?

Solution

What I understand from your question is that you need to create an aspect that knows your methods argument in real time.

There is a useful simple examples in Mkyong's page and probably your need is on point 8.

If you want to get a method name and arguments in your aspect you could write something like this:

@Aspect
public class LoggingAspect {

   @Around("execution(* com.your.package.YourClass.yourMethodAround(..))")
   public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {

    System.out.println("Your method: " + joinPoint.getSignature().getName());
    System.out.println("and method arguments: " + Arrays.toString(joinPoint.getArgs()));

    System.out.println("Your method will be executed. ");
    joinPoint.proceed(); //continue on the intercepted method
    System.out.println("Ended execution");

   }
}

Hope to help

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top