This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests and have Scott Selikoff and Jeanne Boyarsky on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

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

 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Bill.
 
Tell me how it all turns out. Here is a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic