zoukankan      html  css  js  c++  java
  • Clgb动态代理

    public interface ISomeService {
        public void say1();
        public void say2();
        public void say3();
        public void say4();
    }
    接口
     */
    public class MyAfterAdvice implements AfterReturningAdvice {
    
        public void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable {
            System.out.println("后置增强");
        }
    }
    增强
    public class SomeServiceImpl implements ISomeService {
    
        public void say1() {
            System.out.println("1");
        }
    
        public void say2() {
            System.out.println("1");
        }
    
        public void say3() {
            System.out.println("1");
        }
    
        public void say4() {
            System.out.println("1");
        }
    }
    接口实现
    <?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:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="
            http://www.springframework.org/schema/beans
    
     http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/aop
    
     http://www.springframework.org/schema/aop/spring-aop.xsd
    
    ">
    <bean id="service" class="cn.happy.day12aop03.SomeServiceImpl"></bean>
    <bean id="afterAdvice" class="cn.happy.day12aop03.MyAfterAdvice"></bean>
      <bean id="beforeAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
          <property name="advice" ref="afterAdvice"></property>
          <property name="mappedNames" value="*2*"></property>
      </bean>
        <bean id="serviceProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="target" ref="service"></property>
            <property name="interceptorNames" value="beforeAdvisor"></property>
        </bean>
    </beans>
    配置
    public class Test20171012 {
    
       /* @Test
        public void test03(){
            ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext10aop01.xml");
            ISomeService service = (ISomeService) context.getBean("serviceProxy");
           service.say();
        }*/
       /* @Test
        public void test02(){
            ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext11aop02.xml");
            ISomeService service = (ISomeService) context.getBean("serviceProxy");
            service.say();
        }*/
        @Test
        public void test02(){
            ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext12aop03.xml");
            ISomeService service = (ISomeService) context.getBean("serviceProxy");
            service.say1();
            service.say2();
            service.say3();
            service.say4();
    
        }
    
    }
    测试类
  • 相关阅读:
    一款纯css3实现的翻转按钮
    一款基于jquery实现的鼠标单击出现水波特效
    一款由html5 canvas实现五彩小圆圈背景特效
    一款由css3和jquery实现的卡面折叠式菜单
    一款jquery实现的整屏切换特效
    联想笔记本Win10 F1-F12失效的解决方法
    Android笔记:如何在Fragment里使用findViewById()方法?
    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
    Call requires API level 21(Current min is 16)
    Android笔记:DrawerLayout抽屉布局的使用
  • 原文地址:https://www.cnblogs.com/with-lj/p/7678796.html
Copyright © 2011-2022 走看看