By default, Spring generates agents according to the following rules:
When the class has an implementation interface, Spring generates the Jdkdynamicaopproxy proxy
When the class does not implement an interface, Spring generates the Cglibaopproxy proxy
If you want to force spring to generate Cglibaopproxy proxies, you can <aop:config proxy-target-class= "true" > </aop:config>
When you need to use the Cglib Proxy and @aspectj automatic proxy support, set <aop:aspectj-autoproxy>
the properties as follows proxy-target-class
: <aop:aspectj-autoproxy proxy-target-class= "true" />
---------------------------------------------------------------------when implementing an agent through Jdkdynamicaopproxy, How to get to the target object-------------------------------------------------------------
Private static Object Getjdkdynamicproxytargetobject (object proxy) throws Exception {
Field h = Proxy.getclass (). Getsuperclass (). Getdeclaredfield ("H");
H.setaccessible (TRUE);
Aopproxy aopproxy = (aopproxy) h.get (proxy);
Field advised = Aopproxy.getclass (). Getdeclaredfield ("advised");
Advised.setaccessible (TRUE);
Object target = ((Advisedsupport) Advised.get (Aopproxy)). Gettargetsource (). Gettarget ();
return target;
}
--------------------------------------------------------------------when implementing an agent through Cglibaopproxy, How to get the target object---------------------------------------------------------------------------
Private static Object Getcglibproxytargetobject (object proxy) throws Exception {
Field h = Proxy.getclass (). Getdeclaredfield ("Cglib$callback_0");
H.setaccessible (TRUE);
Object Dynamicadvisedinterceptor = h.get (proxy);
Field advised = Dynamicadvisedinterceptor.getclass (). Getdeclaredfield ("advised");
Advised.setaccessible (TRUE);
Object target = ((Advisedsupport) Advised.get (Dynamicadvisedinterceptor)). Gettargetsource (). Gettarget ();
return target;
}
About Spring Dynamic agents