We have to build some Proxy via Cglib, sometimes the "superclass" of the proxy can be another proxy generated by Cglib or CglibAopProxy.
But things become strange after we changing spring from 3.0.6 to 4.2.4. If we use proxy and aop together, neither of them can work, it just invokes the methods of user class directly.(it looks good with spring 3.0.6, don't know why)
I traced into the stack, and found that proxy generated by CglibAopProxy will have fields like:
CGLIB$BOUND=false CGLIB$CALLBACK_0=DynamicAdvisedInterceptor@8186 CGLIB$CALLBACK_1=StaticUnadvisedInterceptor@8535
...
After we use this proxy's class as the superclass of the Enhancer, it looks like:
CGLIB$BOUND=true CGLIB$CALLBACK_0=InvokeHandler@8399 (the MethodInterceptor we added) CGLIB$CALLBACK_1=null ... CGLIB$CALLBACK_6=null ExampleController$$EnhancerBySpringCGLIB$$2ab2772f.CGLIB$BOUND=true ExampleController$$EnhancerBySpringCGLIB$$2ab2772f.CGLIB$CALLBACK_0=null
Inside of the InvokerHandler there is an instance of proxy generated by CglibAopProxy. We will invoke it in the InvokerHandler
We hope an invocation will go into InvokeHandler first, then process aop, then call the user class. But we can never continue since this problem.
well...
I found that cglib and spring's cglib can't detect each other. So, Enhancer.isEnhanced() failed. So, the super class became the CGLIB's Proxy Class. So, the Outside Proxy class is broken.
So, we detect the "$$" in the class name, and if there is any, we go to it's superclass until there is no "$$". Then, It works(maybe).