Spring 代理增强
2017-08-04 08:45
106 查看
[java] view plain copy <span style="font-size:14px;">public interface IDog { public void dog(); public void run(); } public class Dog implements IDog{ public void dog(){ System.out.println("===测试顾问==1dog()"); } public void run() { System.out.println("====测试顾问===2run()"); } } public class MyBefore implements MethodBeforeAdvice { public void before(Method method, Object[] objects, Object o) throws Throwable { System.out.println("======before===="); } }</span> [java] view plain copy <span style="font-size:14px;"><?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" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd "> <bean id="dog" class="cn.springGuWen.Dog"></bean> <bean id="before" class="cn.springGuWen.MyBefore"></bean> <!--顾问 需要增强的方法--> <!--<bean id="GuWen" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor"> <property name="advice" ref="before"></property> <property name="mappedNames" value="run"></property> </bean>--> <!--正则 表达式匹配--> <bean id="GuWen" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name="advice" ref="before"></property> <property name="patterns" value=".*ru.*"></property> </bean> <bean id="TextGuWen" class="org.springframework.aop.framework.ProxyFactoryBean"> <!--需要增强的对象--> <property name="target" ref="dog"></property> <!--需要拦截的方法--> <property name="interceptorNames" value="GuWen"></property> </bean> </beans> </span> [java] view plain copy <span style="font-size:14px;">public class TextGuWen { //测试 顾问 匹配姓名方法 //测试 正则 匹配的 方法 @Test public void aVoid(){ ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext07GuWen.xml"); IDog dog = (IDog)ctx.getBean("TextGuWen"); dog.dog(); System.out.println(); dog.run(); }</span>
相关文章推荐
- spring 代理对象方法增强源码解析
- spring 代理对象方法增强源码解析222222
- ######【spring属性注入(Ioc的DI)总结】:注解方式属性注入,属性名任意.=for理解:Aop注入代理对象时,注入被增强类对象时,属性名为proxy(自定义)。
- Spring 顾问 代理 增强
- Spring 顾问 代理增强
- Spring AOP 自动代理执行增强
- Spring自动创建异常抛出增强代理
- Spring对log4j的增强
- Spring事务代理
- 基于Spring AOP的JDK动态代理和CGLIB代理
- spring 之自动代理
- Spring AOP 中的代理模式
- spring中AOP动态代理基本原理
- Spring三种实现自动代理
- spring 常用注解代理方式及注意点
- Spring 4.3 的新功能和增强
- spring 声明试事务代理
- Spring AOP 代理配置笔记
- SpringAOP原理之---Java动态代理
- spring经典的基于代理的AOP编程-[控制粒度-类]