[Spring] AOP interception-Three ways to implement automatic proxy
The automatic proxy here, I'm talking about the automatic Agent Bean object, in fact, in the XML let us not configure the Agent factory, That is, you do not have to configure a bean with class Org.springframework.aop.framework.ProxyFactoryBean.
With spring an automatic proxy class Defaultadvisorautoproxycreator:
<class= " Org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator "></Bean >
For example:
The original configuration file without automatic proxy is as follows:
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:tx= "Http://www.springframework.org/schema/tx"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-4.3.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/co Ntext/spring-context-4.3.xsd Http://www.springframework.org/schema/tx Http://www.springframework.org/schema /tx/spring-tx-4.3.xsd "> <!--Agent Maehara - <BeanID= "Person"class= "Cn.hncu.xmlImpl.Person"></Bean> <!--Tangent point = tangent + notification - <BeanID= "Advisor"class= "Org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <!--Tangent Point - < Propertyname= "Patterns"> <List> <value>. *run.*</value> </List> </ Property> <!--notification-written by us, actual agent action - < Propertyname= "Advice"> <BeanID= "Advice"class= "Cn.hncu.xmlImpl.AroundAdvice"></Bean> </ Property> </Bean> <!--Agent Factory - <BeanID= "Personproxied"class= "Org.springframework.aop.framework.ProxyFactoryBean"> <!--put into prototype object - < Propertyname= "Target"ref= "Person"></ Property> <!--put into slices - < Propertyname= "Interceptornames"> <List> <value>Advisor</value> </List> </ Property> </Bean></Beans>
Now switch to Automatic proxy, which is configured as follows:
<Beans...><!--Agent Maehara - <BeanID= "Person"class= "Cn.hncu.xmlImpl.Person"></Bean> <!--Tangent point = tangent + notification - <BeanID= "Advisor"class= "Org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <!--Tangent Point - < Propertyname= "Patterns"> <List> <value>. *run.*</value> </List> </ Property> <!--notification-written by us, actual agent action - < Propertyname= "Advice"> <BeanID= "Advice"class= "Cn.hncu.xmlImpl.AroundAdvice"></Bean> </ Property> </Bean>
<!--Automatic proxy - <Beanclass= "Org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"></Bean></Beans>
Test method
@Test// Auto Agent public void Demo4 () { new Classpathxmlapplicationcontext ("Cn/hncu/xmlimpl/4.xml"); // we can get the person object directly here, because after the XML file Newperson object in the beginning, spring has already helped us proxy! person p =ctx.getbean (person. Class); P.run (); P.say (); }
In contrast to the front, that is, the agent factory part of the automatic proxy.
Energy project XML file tag interpretation--defaultadvisorautoproxycreator