• Aop ---- Introductions(简介)---xml实现


    1、Introductions作用:

      允许一个切面声明一个实现指定接口的通知对象,并且提供一个实现类代表这些对象

    2、使用方法:

      在<aop:aspect>中写入<aop:declare-parents/>

    3、例子:

      在xml文件中:

          

      <bean id="test" class="main.ioc.aop.Test"/>
      <bean id="test2" class="main.ioc.aop.Test2"/>
      <aop:config >
        <aop:aspect id="myAspect" ref="test">
          <aop:declare-parents types-matching="main.ioc.aop.*(+)"
                    implement-interface="main.ioc.advice.Fit"
                    default-impl="main.ioc.advice.FitImpl"/>
          </aop:aspect>
      </aop:config>

    4、创建一个接口和实现类Fit、FitImpl:

      

       

    5、测试类:

      

      @Test
      public void test(){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-ioc.xml");
        Fit bean = (Fit)ctx.getBean("test2");
        bean.test();
      }

    6、输出结果:

      

  • 相关阅读:
    关于伸缩盒子的使用问题
    html5前端框架
    ES6 promise对象
    Node和Electron开发入门(四):操作PC端文件系统
    兄弟组件的传值
    端口冲突解决办法
    查看mysql状态的常用命令
    使用mysqldump导入导出MySQL数据库
    Yii CModel中rules验证规则
    URL中#号的含义
  • 原文地址:https://www.cnblogs.com/xl118/p/6786039.html
Copyright © 2020-2023  润新知