This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thank you Bill.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic