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.
as you see, I defined various advices for all the methods of Controller class
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.
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.