zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Single Round Match 811 1~4 题解
    AtCoder Beginner Contest 215 A~F 题解
    Codeforces Round #739 (Div. 3) 题解
    Codeforces Round #737 (Div. 2) A~E 题解
    Codeforces Round #735 (Div. 2) A~D 题解
    CodeChef Starters 6 Division 3 题解
    AtCoder Beginner Contest 209 题解
    Codeforces Round #732 (Div. 2) A~D题解
    【YBTOJ】约数之和
    【Luogu P7794】[COCI2014-2015#7] JANJE
  • 原文地址:https://www.cnblogs.com/diaoniwa/p/6505440.html
Copyright © 2011-2022 走看看