Announcement Announcement Module
Collapse
No announcement yet.
How to Advise Aspects to all the method chai?n Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Advise Aspects to all the method chai?n

    Hi,
    My requirement is to capture the time taken for each method call.

    Code:
    public class Sample
    {
        public static void method1()
        {
              SOP("*********** method1() ***********");
              subMethod1();
        }
        public static void subMethod1()
        {
              SOP("*********** subMethod1() ***********");
        }
    
    }
    
    @Around("execution(public * *(..))")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable 
    {
    	try 
    	{
    	long start = System.currentTimeMillis();
    	System.out.println("Entered into method: "+joinPoint.getSignature().getName());
    	Object object = joinPoint.proceed();
    	System.out.println("Exiting from method: "+joinPoint.getSignature().getName());
    	long end = System.currentTimeMillis();
    	System.out.println("Time taken for Method "+joinPoint.getSignature().getName()+" is :"+(end-start)+" millis");
    	return object;
    	} 
    	catch (IllegalArgumentException e) 
    	{
    		throw e;
    	}
    }
    But with this advise configuration (@Around("execution(public * *(..))")),
    When i get Bean Sample from ApplicationContext and call method1(),
    i am not getting the log statements for subMethod1() .
    Last edited by sivaprasadreddy.k; Jan 21st, 2010, 02:40 AM.

  • #2
    This question has been answered many times, with Spring AOP you can't advice on the calls within the object, only on the calls made to the proxy from outside the class. To advice on the inner calls you need to introduce AspectJ...

    Comment

    Working...
    X