1.默认Advisor自动代理生成器
接口:ISomeService
public interface ISomeService { public void doSome(); public void doSecont();}
类
public class MyAfterReturningAdvice implements AfterReturningAdvice { public void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable { System.out.println("-+-======================after=================-+-"); }}
public class MyBeforeAdvise implements MethodBeforeAdvice { public void before(Method method, Object[] objects, Object o) throws Throwable { System.out.println("==========log=========="); }}
public class SomeService implements ISomeService { //核心业务 public void doSome() { System.out.println("拜托别让他一番努力换来是奢求!"); } public void doSecont() { System.out.println("++===================Secont====================++"); }}
配置文件
单测
//1.默认Advisor自动代理生成器 @Test public void test03(){ ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext07_aop07_defaultzidonAgent.xml"); ISomeService service = (ISomeService) ctx.getBean("someService"); service.doSome(); service.doSecont(); }
2.BeanName自动代理生成器
接口:ISomeService
public interface ISomeService { public void doSome(); public void doSecont();}
类
public class MyBeforeAdvise implements MethodBeforeAdvice { public void before(Method method, Object[] objects, Object o) throws Throwable { System.out.println("==========log=========="); }}
public class SomeService implements ISomeService { //核心业务 public void doSome() { System.out.println("拜托别让他一番努力换来是奢求!"); } public void doSecont() { System.out.println("++===================Secont====================++"); }}
配置文件
单测
//2.BeanName自动代理生成器 @Test public void test04(){ ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext08_aop08_BeanNamezidonAgent.xml"); ISomeService service = (ISomeService) ctx.getBean("someService"); service.doSome(); service.doSecont(); }