Clgb动态代理

Posted with-lj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();

    }

}
测试类

 

以上是关于Clgb动态代理的主要内容,如果未能解决你的问题,请参考以下文章

JAVA之AOP

动态 Rstudio 代码片段

是否可以动态编译和执行 C# 代码片段?

支持动态或静态片段的不同屏幕尺寸?

Forge Viewer - 如何在场景中访问(或获取渲染/片段代理)克隆的网格?

在ansible模板中使用动态组名称