Energy project XML file tag interpretation--defaultadvisorautoproxycreator

Source: Internet
Author: User

[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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.