码迷,mamicode.com
首页 > 其他好文 > 详细

Clgb动态代理

时间:2018-02-28 14:08:38      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:day   接口   row   cto   ext   schema   oid   name   mat   

技术分享图片
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();

    }

}
测试类

 

Clgb动态代理

标签:day   接口   row   cto   ext   schema   oid   name   mat   

原文地址:https://www.cnblogs.com/with-lj/p/7678796.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!