Spring AOP自动代理创建者

Posted 写代码隔扣邓肯

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring AOP自动代理创建者相关的知识,希望对你有一定的参考价值。

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自动代理创建者的主要内容,如果未能解决你的问题,请参考以下文章

Spring AOP自动代理创建者

阿里四面:你知道Spring AOP创建Proxy的过程吗?

Spring读源码系列之AOP--08--aop执行完整源码流程之自动代理创建器导入的两种方式

spring aop

Spring AOP

spring实现aop具体步骤