------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------
RegexpMethodPointcutAdvisor:正则方法切入点顾问
核心:
<property name="pattern" value=".*do.*"></property> 表示方法全名(包名,接口名,方法名)
运算符 名称 意义 . 点号 表示任意单个字符 + 加号 表示前一个字符出现一次或者多次 * 星号 表示前一个字符出现0次或者多次具体使用案例:
一个实现俩个方法的类:SomeServiceImpl
package cn.dawn.day16advisor02;/** * Created by Dawn on 2018/3/8. */public class SomeServiceImpl { public void doSome() { System.out.println("do something"); } public void doAny() { System.out.println("do Any"); }}
一个实现任意增强的接口的方法:此处是实现后置增强的,我起名LoggerAfter
package cn.dawn.day16advisor02;import org.springframework.aop.AfterReturningAdvice;import java.lang.reflect.Method;/** * Created by Dawn on 2018/3/5. *//*后置增强*/public class LoggerAfter implements AfterReturningAdvice { public void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable { System.out.println("===============after=================="); }}
大配置文件:
单测方法:
package cn.dawn.day16advisor02;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;/** * Created by Dawn on 2018/3/3. */public class test20180310 { @Test /*aop代理工厂bean异常增强*/ public void t01(){ ApplicationContext context=new ClassPathXmlApplicationContext("ApplicationContext-day16advisor02.xml"); SomeServiceImpl service = (SomeServiceImpl) context.getBean("proxyfactory"); service.doSome(); service.doAny(); }}