JDK动态代理实现横切逻辑的方法
1、创建接口impl,包括若干方法
2、创建实现类,继承接口,编写具体实现,其中并不包括需要植入的逻辑
3、编写植入的方法,类和具体实现。
4、继承InvocationHandler的方法,将希望被代理的目标业务类的对象传入给Handle的target,通过反射机制调用业务类的目标方法。
5、测试类:ForumService target=new FormServiceImpl();
PerformanceHandle handle=new PerformanceHandle(target);
ForumService proxy= (ForumService)Proxy.newProxyInstance(target.getClass().getClass Loader(), target.getClass().getInterfaces(), handle);
proxy.removeForum(10);
proxy.removeTopic(1012);