反射實現 AOP 動態代理模式(Spring AOP 的實現 原理)
阿新 • • 發佈:2019-02-18
{
40 //反射得到操作者的例項41 Class clazz = this.proxy.getClass();
42 //反射得到操作者的Start方法43 Method start = clazz.getDeclaredMethod("start",
44 new Class[] { Method.class });
45 //反射執行start方法46 start.invoke(this.proxy, new Object[] { method } );
47 //執行要處理物件的原本方法48 result = method.invoke(this.delegate, args);
49// 反射得到操作者的end方法50 Method end = clazz.getDeclaredMethod("end",
51 new Class[] { Method.class });
52// 反射執行end方法53 end.invoke(this.proxy, new Object[] { method } );
54
55 }
40 //反射得到操作者的例項41 Class clazz = this.proxy.getClass();
42 //反射得到操作者的Start方法43 Method start = clazz.getDeclaredMethod("start",
44 new Class[] { Method.class });
45 //反射執行start方法46 start.invoke(this.proxy, new Object[] { method }
47 //執行要處理物件的原本方法48 result = method.invoke(this.delegate, args);
49// 反射得到操作者的end方法50 Method end = clazz.getDeclaredMethod("end",
51 new Class[] { Method.class });
52// 反射執行end方法53 end.invoke(this.proxy, new Object[] { method }
54
55 }