I use spring-aop-5.2.15.RELEASE.
Now if one bean's method call its' own internal method, it seems that the called method does not take effect with interceptor. I know this has been discussed before, and I've searched elsewhere, the framework recommends using @Autowired
to inject a proxy object. But it doesn't seem elegant.
I find in DynamicAdvisedInterceptor
if (chain.isEmpty() && Modifier.isPublic(method.getModifiers())) {
// We can skip creating a MethodInvocation: just invoke the target directly.
// Note that the final invoker must be an InvokerInterceptor, so we know
// it does nothing but a reflective operation on the target, and no hot
// swapping or fancy proxying.
Object[] argsToUse = AopProxyUtils.adaptArgumentsIfNecessary(method, args);
retVal = methodProxy.invoke(target, argsToUse);
}
I don't understand why retVal = methodProxy.invoke(target, argsToUse);
Maybe retVal = methodProxy.invokeSuper(proxy, argsToUse);
is better in sometimes.
I also looked at the @Lookup
code, which directly uses Cglib as a proxy for calls between methods within a class.
How about replacing invoke with invokeSuper? Or allow the API caller to configure which method to use? Of course, my understanding of it is relatively simple.
Comment From: snicoll
Thanks for the report and sorry it got overlooked. Support self invocation could easily lead to an infinite loop. We usually recommend creating a facade and separate the layers so that the aspect is "behind" the facade and does not require self invocation in the first place. There is also a request from the community to make our recommendations a bit more apparent, please subscribe to #28299.