zoukankan      html  css  js  c++  java
  • 能源项目xml文件标签释义--DefaultAdvisorAutoProxyCreator

    [Spring]AOP拦截-三种方式实现自动代理

    这里的自动代理,我讲的是自动代理bean对象,其实就是在xml中让我们不用配置代理工厂,也就是不用配置class为org.springframework.aop.framework.ProxyFactoryBean的bean。

    用Spring一个自动代理类DefaultAdvisorAutoProxyCreator:

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

    例如: 
    原来不用自动代理的配置文件如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="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/context/spring-context-4.3.xsd
                    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    
        <!-- 代理前原对象 -->
        <bean id="person" class="cn.hncu.xmlImpl.Person"></bean>
    
        <!-- 切面 = 切点+通知 -->
        <bean id="advisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
            <!-- 切点 -->
            <property name="patterns">
                <list>
                    <value>.*run.*</value>
                </list>
            </property>
            <!-- 通知-由我们写,实际代理动作 -->
            <property name="advice">
                <bean id="advice" class="cn.hncu.xmlImpl.AroundAdvice"></bean>
            </property>
        </bean>
    
        <!-- 代理工厂 -->
        <bean id="personProxied" class="org.springframework.aop.framework.ProxyFactoryBean">
            <!-- 放入原型对象 -->
            <property name="target" ref="person"></property>
    
            <!-- 放入切面 -->
            <property name="interceptorNames">
                <list>
                    <value>advisor</value>
                </list>
            </property>
        </bean>
    </beans>

    现在改用自动代理,如下配置:

    <beans ...>
    <!-- 代理前原对象 -->
        <bean id="person" class="cn.hncu.xmlImpl.Person"></bean>
    
        <!-- 切面 = 切点+通知 -->
        <bean id="advisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
            <!-- 切点 -->
            <property name="patterns">
                <list>
                    <value>.*run.*</value>
                </list>
            </property>
            <!-- 通知-由我们写,实际代理动作 -->
            <property name="advice">
                <bean id="advice" class="cn.hncu.xmlImpl.AroundAdvice"></bean>
            </property>
        </bean>

    <!-- 自动代理 --> <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"></bean> </beans>

    测试方法

      @Test//自动代理
        public void demo4(){
            ApplicationContext ctx = new ClassPathXmlApplicationContext("cn/hncu/xmlImpl/4.xml");
            //我们直接在这里获取Person对象就可以了,因为在最开始xml文件newPerson对象后,Spring就已经帮我们代理了!
            Person p =ctx.getBean(Person.class);
            p.run();
            p.say();
        }

    相对于前面,也就是把代理工厂部分换成自动代理了。

  • 相关阅读:
    Qt制作应用插件
    isHiden和isVisible的区别(isVisible更可靠)
    QT解析命令行(QCommandLineOption和QCommandLineParser类)
    delphi 各新版本特性收集
    java遍历Set集合
    全局忽略编译警告(设置QMAKE_CXXFLAGS )
    配置QtCreator+CDB远程调试环境(要设置_NT_SYMBOL_PATH和QT_PLUGIN_PATH和Path)
    设置程序版本等信息(可直接修改pro文件设置,但是更推荐使用rc文件设置)
    移动无边框窗体(设置标志位更流畅,或者发送WM_SYSCOMMAND和SC_MOVE + HTCAPTION消息)
    让VC2012生成的程序支持XP系统(修改mkspecswin32-msvc2012qmake.conf,QT的DLL都是支持XP的,只与EXE有关)good
  • 原文地址:https://www.cnblogs.com/ClassNotFoundException/p/6031281.html
Copyright © 2011-2022 走看看