Do you mean, how do you get the proxy? I got it using AopContext.currentProxy().
Do you mean, how do you get the proxy? I got it using AopContext.currentProxy().
A little introduction to my situation:
I am facing the same problem that you had, but instead of swapping the target, I just needed to modify the method arguments. I created a PreInterceptor, where I have the following code:
Object[] arguments = invocation.getArguments();
Class object = (Class) arguments[0];
object.setProperty = false;
Advised advised = (Advised) AopContext.currentProxy();
Object proxy = (Object) AopContext.currentProxy();
Object target = (Object) advised.getTargetSource().getTarget();
arguments[0] = object;
//return invocation.getMethod().invoke(target,arguments);
return invocation.getMethod().invoke(proxy,arguments);
Note: I changed the actual Class, object and setProperty to generic words for the sample code.
If I use "target" in the invoke method, the postInterceptor is skipped (which is what you found). If I use "proxy", it gets into a loop, calling the PreInterceptor over and over... Any ideas?
Thanks in advance for your help
I seem to recall that I wrote an interceptor that modified the arguments, and just calling methodInterceptor.proceed() worked properly.