aspose file tools*
The moose likes Spring and the fly likes Unable to invoke aspects for the public nested method calls using Spring AOP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Unable to invoke aspects for the public nested method calls using Spring AOP" Watch "Unable to invoke aspects for the public nested method calls using Spring AOP" New topic
Forums: Spring Aspect Oriented Programming
Author

Unable to invoke aspects for the public nested method calls using Spring AOP

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 516
    
    2

Hello All,

I'm trying to learn Spring and its support for AOP, using Spring AOP features. I'm using Spring 3.2.3, aspectj 1.7.2 and have all the dependencies properly made available.

configuration file


ControllerLoggingAspect.java


as you see, I defined various advices for all the methods of Controller class

Controller.java


All the methods in Controller.java are public and I enabled proxy to the class using cglib.

My expectation is, the advices should be invoked (before, after, around, after returning) for each method call beginning from MethodA,MethodB,MethodC in sequence

However, when I ran the output I see is as follows


Why am I not able to see @Around or any other advice for the whole method call stack, why just MethodA. Does these advices get invoked only for the first method call, not the nested. What should I need to do to enable that.

I understand that basic support of AOP and AspectJ by Spring does not include advices around private methods to be invoked and I read that it requires aspectJ programming instead. Is that true for even the public nested method calls.

Since I used Controller.*(..), I thought all the public methods are covered. Please help me understand this.

Thanks

Regards
KumarRaja

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

You are using Spring's proxy based AOP. So you have to invoke the method through the proxy for the advice to be applied. You are calling A through the proxy so you get the print out. However the call to B and C are what I like to call self calls. They are the class calling another method within itself they are not going through the proxy. If you want to remove this limitation (and the need for public methods as well) then you have to use full AspectJ and configure your POM file to weave in the aspects during compilation. You also then have the added advantage of seeing the aspect markers in eclipse. Alternatively if you call B and C in the same manner you call A, you will see all 3.


[How To Ask Questions][Read before you PM me]
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 516
    
    2

Thank you Bill.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to invoke aspects for the public nested method calls using Spring AOP
 
Similar Threads
Execption in AOP Logging Program Issue
Spring AOP with mvc
Problem with Spring AOP+AspectJ
AOP Not working with Spring 3 MVC application
Wierd Case with Spring AOP