I think I have a solution for the above problem.
Problem :
public class MyService {
public methodA()
{
//do something
methodB();
//do something
}
public methodB()
{
//do something else
}
}
Now both the method in the service have been AOPed, and when I call the methodA() on the proxied instance, the methodA() will have the benefit of the aspect, but when the methodB() gets called from methodA(), it would not get that benefit of AOP.
The problem here is that methodA() call on the proxied object, after doing the aspect stuff, forwards the call to the target's method (in this case MyService.methodA()). And when methodB() get called, it is called on the MyService's instance, and not on the proxied object, hence the methodB() not getting the benefit of the aspect.
Solution:
The above problem can be solved by forcing the proxy class to be extended from the target class (in this case MyService). Any method invoked on the proxy class, would then instead of forwarding the call to the target's method, would call the super method of the target class (super.methodA() in this case). Hence, when the methodB() gets called from methodA(), it would be invoked on the proxied instance, hence the aspected stuff would be called for the methodB() as well.
To achieve the above, you would have to do the following :
a) force the class to be proxed by extending the target class. This can be done as below in the application context file:
<property name="proxyTargetClass">
<value>true</value>
</property>
b) This is more important :
You have to change the code in the static class Cglib2AopProxy.CglibMethodInvocation's
from :
protected Object invokeJoinpoint() throws Throwable {
return this.methodProxy.invoke(this.target, this.arguments);
}
to :
protected Object invokeJoinpoint() throws Throwable {
//call the super() on the proxied object
return this.methodProxy.invokeSuper(this.proxy, this.arguments);
}
This should solve the problem. I not sure if there are any issues with this approach. I would appreciate if someone could let me know their feedback on this approach.
Also, if there are major issue, it would be a great help, if Spring can provide this flexiblity of invoking the super() instead of the actual method.
Thanks a ton,
Amit Chhajed


Reply With Quote
, but just as FYI, I see that spring.net is moving in the same direction: 