设为首页 加入收藏

TOP

Spring AOP的两种代理(二)
2015-11-12 23:05:55 来源: 作者: 【 】 浏览:21
Tags:Spring AOP 代理
ject[] args,
? ? ? ? ? ? MethodProxy methodproxy) throws Throwable {? ? ? ?
? ? ? ? Object result = null;? ?
? ? ? ? try {
? ? ? ? ? ? ? System. out .println( "前置处理开始 ..." );
? ? ? ? ? ? ? result = methodproxy.invoke( targetObject , args);//执行目标对象的方法
? ? ? ? ? ? ? System. out .println( "后置处理开始? ..." );
? ? ? ? ? } catch (Exception e) {
? ? ? ? ? ? ? System. out .println( " 异常处理 ..." );
? ? ? ? ? } finally {
? ? ? ? ? ? ? System. out .println( " 调用结束 ..." );
? ? ? ? ? }
? ? ? ? ? return result;
? ? ? }?
? }
测试类:


? public class TestCGLIBProxy {


? ? ? ? public static void main(String[] args) {
? ? ? ?
? ? ? ? ? //我们要代理的真实对象
? ? ? ? ? TestCGLIBServiceImpl testCGLIB = new TestCGLIBServiceImpl();
? ? ? ? ? CGLIBProxy CGLIBproxy = new CGLIBProxy();
? ? ? ? ? TestCGLIBServiceImpl testCGLIBProxy = (TestCGLIBServiceImpl) CGLIBproxy.createProxyInstance(testCGLIB);
? ? ? ? ? testCGLIBProxy.add();
? ? ? }
? }


结果图:



写在后面:spring AOP的两种代理实现代码就写到这,这里只是实现了,如果你要想真正明白,还得熟悉其中原理机制,比如反射机制,newProxyInstance(...),Enhancer()原理,invoke()原理等等。


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇【R】用 ggplot2 绘制漂亮的分级.. 下一篇Spring AOP的注解实例

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: