什么是顾问?什么是通知?
顾问:从字面意思来讲,只找固定的几个可以使用
通知:所有的都可以用
举例说明通知
创建接口和实现类
package cn.happy.day11ProxyFactory;/** * Created by Administrator on 2018/3/8. */public interface ISomeService { public void doSome(); public void doAny();} package cn.happy.day11ProxyFactory;/** * Created by Administrator on 2018/3/8. */public class SomeServiceImpl implements ISomeService { public void doSome() { System.out.println("do Something"); } public void doAny() { System.out.println("do Any"); }}
创建一个类
package cn.happy.day11ProxyFactory;import org.springframework.aop.MethodBeforeAdvice;import java.lang.reflect.Method;/** * Created by Administrator on 2018/3/8. */public class BeforeAdvice implements MethodBeforeAdvice { public void before(Method method, Object[] objects, Object o) throws Throwable { System.out.println("我是通知"); }}
配置xml
测试结果
通知是针对所有的方法进行
顾问
只需修改xml文件配置即可,
测试: