码迷,mamicode.com
首页 > 编程语言 > 详细

Spring AOP自动代理创建者

时间:2017-03-05 15:42:32      阅读:391      评论:0      收藏:0      [点我收藏+]

标签:advice   work   property   eth   aic   top   names   mapped   iso   

1. BeanNameAutoProxyCreator示例

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="customerService" class=customer.services.CustomerService">
        <property name="name" value="" />
        <property name="url" value="www.baidu.com" />
    </bean>

    <bean id="hijackAroundMethodBeanAdvice" class="com.yiibai.aop.HijackAroundMethod" />

    <bean id="customerAdvisor"
        class="org.springframework.aop.support.NameMatchMethodYiibaicutAdvisor">
        <property name="mappedName" value="printName" />
        <property name="advice" ref="hijackAroundMethodBeanAdvice" />
    </bean>
  <!-- BeanNameAutoProoxyCreator -->
    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="beanNames">
            <list>
                <value>*Service</value>
            </list>
        </property>
        <property name="interceptorNames">
            <list>
                <value>customerAdvisor</value>
            </list>
        </property>
    </bean>
</beans>

2. DefaultAdvisorAutoProxyCreator示例

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="customerService" class="customer.services.CustomerService">
        <property name="name" value="xiaoming" />
        <property name="url" value="www.baidu.com" />
    </bean>

    <bean id="hijackAroundMethodBeanAdvice" class="aop.HijackAroundMethod" />

    <bean id="customerAdvisor"
        class="org.springframework.aop.support.NameMatchMethodYiibaicutAdvisor">
        <property name="mappedName" value="printName" />
        <property name="advice" ref="hijackAroundMethodBeanAdvice" />
    </bean>

       <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />

</beans>

 

Spring AOP自动代理创建者

标签:advice   work   property   eth   aic   top   names   mapped   iso   

原文地址:http://www.cnblogs.com/diaoniwa/p/6505440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!