<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)

    好長(zhǎng)時(shí)間沒(méi)有用過(guò)Spring了. 突然拿起書.我都發(fā)現(xiàn)自己對(duì)AOP都不熟悉了.
    其實(shí)AOP的意思就是面向切面編程.
    OO注重的是我們解決問(wèn)題的方法(封裝成Method),而AOP注重的是許多解決解決問(wèn)題的方法中的共同點(diǎn),是對(duì)OO思想的一種補(bǔ)充!
    還是拿人家經(jīng)常舉的一個(gè)例子講解一下吧:
    比如說(shuō),我們現(xiàn)在要開(kāi)發(fā)的一個(gè)應(yīng)用里面有很多的業(yè)務(wù)方法,但是,我們現(xiàn)在要對(duì)這個(gè)方法的執(zhí)行做全面監(jiān)控,或部分監(jiān)控.也許我們就會(huì)在要一些方法前去加上一條日志記錄,
    我們寫個(gè)例子看看我們最簡(jiǎn)單的解決方案
    我們先寫一個(gè)接口IHello.java代碼如下:
     1package sinosoft.dj.aop.staticaop;
     2
     3public interface IHello {
     4    /**
     5     * 假設(shè)這是一個(gè)業(yè)務(wù)方法
     6     * @param name
     7     */

     8    void sayHello(String name);
     9}

    10

    里面有個(gè)方法,用于輸入"Hello" 加傳進(jìn)來(lái)的姓名;我們?nèi)憘€(gè)類實(shí)現(xiàn)IHello接口
    package sinosoft.dj.aop.staticaop;

    public class Hello implements IHello {

        
    public void sayHello(String name) {
            System.out.println(
    "Hello " + name);
        }


    }


    現(xiàn)在我們要為這個(gè)業(yè)務(wù)方法加上日志記錄的業(yè)務(wù),我們?cè)诓桓淖冊(cè)a的情況下,我們會(huì)去怎么做呢?也許,你會(huì)去寫一個(gè)類去實(shí)現(xiàn)IHello接口,并依賴Hello這個(gè)類.代碼如下:
     1package sinosoft.dj.aop.staticaop;
     2
     3public class HelloProxy implements IHello {
     4    private IHello hello;
     5
     6    public HelloProxy(IHello hello) {
     7        this.hello = hello;
     8    }

     9
    10    public void sayHello(String name) {
    11        Logger.logging(Level.DEBUGE, "sayHello method start.");
    12        hello.sayHello(name);
    13        Logger.logging(Level.INFO, "sayHello method end!");
    14
    15    }

    16
    17}

    18

    其中.Logger類和Level枚舉代碼如下:
    Logger.java
     1package sinosoft.dj.aop.staticaop;
     2
     3import java.util.Date;
     4
     5public class Logger{
     6    /**
     7     * 根據(jù)等級(jí)記錄日志
     8     * @param level
     9     * @param context
    10     */

    11    public static void logging(Level level, String context) {
    12        if (level.equals(Level.INFO)) {
    13            System.out.println(new Date().toLocaleString() + " " + context);
    14        }

    15        if (level.equals(Level.DEBUGE)) {
    16            System.err.println(new Date() + " " + context);
    17        }

    18    }

    19
    20}

    21
    Level.java

    1package sinosoft.dj.aop.staticaop;
    2
    3public enum Level {
    4    INFO,DEBUGE;
    5}

    6
    那我們?nèi)憘€(gè)測(cè)試類看看,代碼如下:
    Test.java
    1package sinosoft.dj.aop.staticaop;
    2
    3public class Test {
    4    public static void main(String[] args) {
    5        IHello hello = new HelloProxy(new Hello());
    6        hello.sayHello("Doublej");
    7    }

    8}

    9
    運(yùn)行以上代碼我們可以得到下面結(jié)果:

    Tue Mar 04 20:57:12 CST 2008 sayHello method start.
    Hello Doublej
    2008-3-4 20:57:12 sayHello method end!

    從上面的代碼我們可以看出,hello對(duì)象是被HelloProxy這個(gè)所謂的代理態(tài)所創(chuàng)建的.這樣,如果我們以后要把日志記錄的功能去掉.那我們只要把得到hello對(duì)象的代碼改成以下:
    1package sinosoft.dj.aop.staticaop;
    2
    3public class Test {
    4    public static void main(String[] args) {
    5        IHello hello = new Hello();
    6        hello.sayHello("Doublej");
    7    }

    8}

    9

    上面代碼,可以說(shuō)是AOP最簡(jiǎn)單的實(shí)現(xiàn)!
    但是我們會(huì)發(fā)現(xiàn)一個(gè)問(wèn)題,如果我們像Hello這樣的類很多,那么,我們是不是要去寫很多個(gè)HelloProxy這樣的類呢.沒(méi)錯(cuò),是的.其實(shí)也是一種很麻煩的事.在jdk1.3以后.jdk跟我們提供了一個(gè)API   java.lang.reflect.InvocationHandler的類. 這個(gè)類可以讓我們?cè)贘VM調(diào)用某個(gè)類的方法時(shí)動(dòng)態(tài)的為些方法做些什么事.讓我們把以上的代碼改一下來(lái)看看效果.
    同樣,我們寫一個(gè)IHello的接口和一個(gè)Hello的實(shí)現(xiàn)類.在接口中.我們定義兩個(gè)方法;代碼如下 :

    IHello.java
     1package sinosoft.dj.aop.proxyaop;
     2
     3public interface IHello {
     4    /**
     5     * 業(yè)務(wù)處理A方法
     6     * @param name
     7     */

     8    void sayHello(String name);
     9    /**
    10     * 業(yè)務(wù)處理B方法
    11     * @param name
    12     */

    13    void sayGoogBye(String name);
    14}

    15


    Hello.java

     1package sinosoft.dj.aop.proxyaop;
     2
     3public class Hello implements IHello {
     4
     5    public void sayHello(String name) {
     6        System.out.println("Hello " + name);
     7    }

     8    public void sayGoogBye(String name) {
     9        System.out.println(name+" GoodBye!");
    10    }

    11}

    12

    我們一樣的去寫一個(gè)代理類.只不過(guò).讓這個(gè)類去實(shí)現(xiàn)java.lang.reflect.InvocationHandler接口,代碼如下:
     1package sinosoft.dj.aop.proxyaop;
     2
     3import java.lang.reflect.InvocationHandler;
     4import java.lang.reflect.Method;
     5import java.lang.reflect.Proxy;
     6
     7public class DynaProxyHello implements InvocationHandler {
     8
     9    /**
    10     * 要處理的對(duì)象(也就是我們要在方法的前后加上業(yè)務(wù)邏輯的對(duì)象,如例子中的Hello)
    11     */

    12    private Object delegate;
    13
    14    /**
    15     * 動(dòng)態(tài)生成方法被處理過(guò)后的對(duì)象 (寫法固定)
    16     * 
    17     * @param delegate
    18     * @param proxy
    19     * @return
    20     */

    21    public Object bind(Object delegate) {
    22        this.delegate = delegate;
    23        return Proxy.newProxyInstance(
    24                this.delegate.getClass().getClassLoader(), this.delegate
    25                        .getClass().getInterfaces(), this);
    26    }

    27    /**
    28     * 要處理的對(duì)象中的每個(gè)方法會(huì)被此方法送去JVM調(diào)用,也就是說(shuō),要處理的對(duì)象的方法只能通過(guò)此方法調(diào)用
    29     * 此方法是動(dòng)態(tài)的,不是手動(dòng)調(diào)用的
    30     */

    31    public Object invoke(Object proxy, Method method, Object[] args)
    32            throws Throwable {
    33        Object result = null;
    34        try {
    35            //執(zhí)行原來(lái)的方法之前記錄日志
    36            Logger.logging(Level.DEBUGE, method.getName() + " Method end .");
    37            
    38            //JVM通過(guò)這條語(yǔ)句執(zhí)行原來(lái)的方法(反射機(jī)制)
    39            result = method.invoke(this.delegate, args);
    40            //執(zhí)行原來(lái)的方法之后記錄日志
    41            Logger.logging(Level.INFO, method.getName() + " Method Start!");
    42        }
     catch (Exception e) {
    43            e.printStackTrace();
    44        }

    45        //返回方法返回值給調(diào)用者
    46        return result;
    47    }

    48
    49}

    50

    上面類中出現(xiàn)的Logger類和Level枚舉還是和上一上例子的實(shí)現(xiàn)是一樣的.這里就不貼出代碼了.

    讓我們寫一個(gè)Test類去測(cè)試一下.代碼如下:
    Test.java
     1package sinosoft.dj.aop.proxyaop;
     2
     3public class Test {
     4    public static void main(String[] args) {
     5        IHello hello = (IHello)new DynaProxyHello().bind(new Hello());
     6        hello.sayGoogBye("Double J");
     7        hello.sayHello("Double J");
     8        
     9    }

    10}

    11

    運(yùn)行輸出的結(jié)果如下:
    Tue Mar 04 21:24:03 CST 2008 sayGoogBye Method end .
    Double J GoodBye!
    2008-3-4 21:24:03 sayGoogBye Method Start!
    Tue Mar 
    04 21:24:03 CST 2008 sayHello Method end .
    Hello Double J
    2008-3-4 21:24:03 sayHello Method Start!

    由于線程的關(guān)系,第二個(gè)方法的開(kāi)始出現(xiàn)在第一個(gè)方法的結(jié)束之前.這不是我們所關(guān)注的!
    從上面的例子我們看出.只要你是采用面向接口編程,那么,你的任何對(duì)象的方法執(zhí)行之前要加上記錄日志的操作都是可以的.他(DynaPoxyHello)自動(dòng)去代理執(zhí)行被代理對(duì)象(Hello)中的每一個(gè)方法,一個(gè)java.lang.reflect.InvocationHandler接口就把我們的代理對(duì)象和被代理對(duì)象解藕了.但是,我們又發(fā)現(xiàn)還有一個(gè)問(wèn)題,這個(gè)DynaPoxyHello對(duì)象只能跟我們?nèi)ピ诜椒ㄇ昂蠹由先罩居涗浀牟僮?我們能不能把DynaPoxyHello對(duì)象和日志操作對(duì)象(Logger)解藕呢?
    結(jié)果是肯定的.讓我們來(lái)分析一下我們的需求.
    我們要在被代理對(duì)象的方法前面或者后面去加上日志操作代碼(或者是其它操作的代碼),
    那么,我們可以抽象出一個(gè)接口,這個(gè)接口里就只有兩個(gè)方法,一個(gè)是在被代理對(duì)象要執(zhí)行方法之前執(zhí)行的方法,我們?nèi)∶麨閟tart,第二個(gè)方法就是在被代理對(duì)象執(zhí)行方法之后執(zhí)行的方法,我們?nèi)∶麨閑nd .接口定義如下 :
     1package sinosoft.dj.aop.proxyaop;
     2
     3import java.lang.reflect.Method;
     4
     5public interface IOperation {
     6    /**
     7     * 方法執(zhí)行之前的操作
     8     * @param method
     9     */

    10    void start(Method method);
    11    /**
    12     * 方法執(zhí)行之后的操作
    13     * @param method
    14     */

    15    void end(Method method);
    16}

    17

    我們?nèi)懸粋€(gè)實(shí)現(xiàn)上面接口的類.我們把作他真正的操作者,如下面是日志操作者的一個(gè)類:
    LoggerOperation.java
    package sinosoft.dj.aop.proxyaop;

    import java.lang.reflect.Method;

    public class LoggerOperation implements IOperation {

        
    public void end(Method method) {
            Logger.logging(Level.DEBUGE, method.getName() 
    + " Method end .");
        }


        
    public void start(Method method) {
            Logger.logging(Level.INFO, method.getName() 
    + " Method Start!");
        }


    }


    然后我們要改一下代理對(duì)象DynaProxyHello中的代碼.如下:
     1package sinosoft.dj.aop.proxyaop;
     2
     3import java.lang.reflect.InvocationHandler;
     4import java.lang.reflect.Method;
     5import java.lang.reflect.Proxy;
     6
     7public class DynaProxyHello implements InvocationHandler {
     8    /**
     9     * 操作者
    10     */

    11    private Object proxy;
    12    /**
    13     * 要處理的對(duì)象(也就是我們要在方法的前后加上業(yè)務(wù)邏輯的對(duì)象,如例子中的Hello)
    14     */

    15    private Object delegate;
    16
    17    /**
    18     * 動(dòng)態(tài)生成方法被處理過(guò)后的對(duì)象 (寫法固定)
    19     * 
    20     * @param delegate
    21     * @param proxy
    22     * @return
    23     */

    24    public Object bind(Object delegate,Object proxy) {
    25        
    26        this.proxy = proxy;
    27        this.delegate = delegate;
    28        return Proxy.newProxyInstance(
    29                this.delegate.getClass().getClassLoader(), this.delegate
    30                        .getClass().getInterfaces(), this);
    31    }

    32    /**
    33     * 要處理的對(duì)象中的每個(gè)方法會(huì)被此方法送去JVM調(diào)用,也就是說(shuō),要處理的對(duì)象的方法只能通過(guò)此方法調(diào)用
    34     * 此方法是動(dòng)態(tài)的,不是手動(dòng)調(diào)用的
    35     */

    36    public Object invoke(Object proxy, Method method, Object[] args)
    37            throws Throwable {
    38        Object result = null;
    39        try {
    40            //反射得到操作者的實(shí)例
    41            Class clazz = this.proxy.getClass();
    42            //反射得到操作者的Start方法
    43            Method start = clazz.getDeclaredMethod("start",
    44                    new Class[] { Method.class });
    45            //反射執(zhí)行start方法
    46            start.invoke(this.proxy, new Object[] { method });
    47            //執(zhí)行要處理對(duì)象的原本方法
    48            result = method.invoke(this.delegate, args);
    49//            反射得到操作者的end方法
    50            Method end = clazz.getDeclaredMethod("end",
    51                    new Class[] { Method.class });
    52//            反射執(zhí)行end方法
    53            end.invoke(this.proxy, new Object[] { method });
    54
    55        }
     catch (Exception e) {
    56            e.printStackTrace();
    57        }

    58        return result;
    59    }

    60
    61}

    62

    然后我們把Test.java中的代碼改一下.測(cè)試一下:
    package sinosoft.dj.aop.proxyaop;

    public class Test {
        
    public static void main(String[] args) {
            IHello hello 
    = (IHello)new DynaProxyHello().bind(new Hello(),new LoggerOperation());
            hello.sayGoogBye(
    "Double J");
            hello.sayHello(
    "Double J");
            
        }

    }

    結(jié)果還是一樣的吧.

    如果你想在每個(gè)方法之前加上日志記錄,而不在方法后加上日志記錄.你就把LoggerOperation類改成如下:
     1package sinosoft.dj.aop.proxyaop;
     2
     3import java.lang.reflect.Method;
     4
     5public class LoggerOperation implements IOperation {
     6
     7    public void end(Method method) {
     8        //Logger.logging(Level.DEBUGE, method.getName() + " Method end .");
     9    }

    10
    11    public void start(Method method) {
    12        Logger.logging(Level.INFO, method.getName() + " Method Start!");
    13    }

    14
    15}

    16

    運(yùn)行一下.你就會(huì)發(fā)現(xiàn),每個(gè)方法之后沒(méi)有記錄日志了. 這樣,我們就把代理者和操作者解藕了!

    下面留一個(gè)問(wèn)題給大家,如果我們不想讓所有方法都被日志記錄,我們應(yīng)該怎么去解藕呢.?
    我的想法是在代理對(duì)象的public Object invoke(Object proxy, Method method, Object[] args)方法里面加上個(gè)if(),對(duì)傳進(jìn)來(lái)的method的名字進(jìn)行判斷,判斷的條件存在XML里面.這樣我們就可以配置文件時(shí)行解藕了.如果有興趣的朋友可以把操作者,被代理者,都通過(guò)配置文件進(jìn)行配置 ,那么就可以寫一個(gè)簡(jiǎn)單的SpringAOP框架了.

    posted on 2008-03-04 21:59 DoubleJ 閱讀(68171) 評(píng)論(77)  編輯  收藏 所屬分類: 設(shè)計(jì)模式

    評(píng)論

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-03-04 22:44 魔域私服

    http://www.zhaomysf.com.cn  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-03-05 09:20 久城

    一直想好好學(xué)習(xí)一下AOP!~

    樓主思路很清晰,學(xué)習(xí)了!~  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-03-05 09:58 daya

    很好的一篇文章!
    我也好久沒(méi)做關(guān)于AOP了,都快忘了。
    被樓主一說(shuō),清醒了不少~  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2008-03-05 11:32 paul

    java的代理功能只能代理接口啊,如果要代理類的化,spring用cglib之類的來(lái)增強(qiáng)  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-03-05 11:55 zhe

    非常好,感謝樓主發(fā)表的文章,  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2008-03-12 08:39 Doublej

    代理接口和代理類是一個(gè)道理!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-03-13 14:47 snow

    很不錯(cuò)的文章,學(xué)習(xí)了!!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-04-25 11:04 Rod.Johnson

    很好很經(jīng)典。讓我受益很深呀  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2008-07-08 22:44 菜鳥(niǎo)

    真不錯(cuò),又學(xué)了一招。  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-07-23 15:56 tiantuo

    很好!謝謝!!!!
      回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2008-07-23 23:19 abc

    good!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-09-10 10:18 paladin

    罷錯(cuò)...樓主是好人吶...  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2008-09-25 23:03 james

    good point  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-11-20 14:58 gyf

    thanks,
    good work!!!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2008-12-04 17:20 fds

    buguoyoudiannanya   回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-01-08 23:26 xiaomayi

    謝謝樓主,好人呀。  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-01-15 10:07 吳文文

    非常感謝你的講解  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-02-03 16:07 路過(guò)的人

    不錯(cuò),樓主是個(gè)好人。  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-02-12 13:51 xx

    很不錯(cuò),作者對(duì)AOP非常的精通啊,贊一個(gè)。  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-03-14 22:26 屠夫狀元

    樓主講得不錯(cuò),在此謝過(guò)  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-03-18 17:12 11

    不熟悉你還在這里瞎叫  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-03-23 11:51 22

    內(nèi)容倒是不錯(cuò),有些地方的理解有些偏差。。。  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2009-03-26 18:46 Doublej

    @22
    呵呵。 我現(xiàn)在又很久沒(méi)做了! 有時(shí)間有機(jī)會(huì)討論討論民!!!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2009-03-27 16:42 lighter

    寫的非常好,總算對(duì)動(dòng)態(tài)代理模式有些了解了,謝謝.  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-03-30 11:49 allnen

    好,思路流暢清晰,可以去當(dāng)老師啊,哈哈!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2009-04-14 16:15 sweet

    樓主也是sinosoft的,我也是,崇拜您啊!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-04-15 17:57 xinmu

    內(nèi)容不錯(cuò)啊,如果能把配置文件在解析一番就更加完美了,希望樓主能不吝為我們這些愛(ài)好者剖析一番,非常感謝!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-05-14 14:09 lw

    謝謝 ,學(xué)習(xí)中 ,解釋的很清楚.  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-05-14 17:53 liner

    呵呵,不錯(cuò),思路很清晰  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-05-17 22:28 xiaoyi

    看了又看啊  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-07-01 09:44 詳詳細(xì)細(xì)

    不錯(cuò)  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-07-05 23:20 luguo

    太感謝樓主了  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-07-08 11:38 fleity liu

    看了很多文章,感覺(jué)lz的這篇文章確實(shí)不錯(cuò)。
    有時(shí)間,我想學(xué)習(xí)一下Java語(yǔ)言本身是怎么實(shí)現(xiàn)這些代理的

    這個(gè)blog趕緊收藏了  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-07-17 10:07 mfkiceeq

    樓主,文章相當(dāng)不錯(cuò),看了獲益良多  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-07-21 17:31 sy

    非常好的文章,贊  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-07-25 12:34 wrf

    非常好的文章
      回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-08-14 15:44 simba

    好文章,分析由淺入深  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-11-27 09:13 好!

    非常好!謝謝!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2009-12-07 12:57 dytes

    的確不錯(cuò),這兩天剛看了點(diǎn)AOP方面的文章,理論居多,看的一頭霧水。樓主這篇博文,清晰簡(jiǎn)單易懂,受益匪淺啊。  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2010-05-20 17:34 ddd

    寫的亂七八糟的  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2010-07-07 17:24 丹丹

    @paul
    good  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2010-07-21 11:43 df

    很清晰。。  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2010-08-10 20:17 SGY

    用簡(jiǎn)單的語(yǔ)言講的很透徹。贊一個(gè)  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2010-10-08 13:54 asdtiang

    mark study  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2010-11-23 10:34 lwch

    樓主總結(jié)得太棒了~~~很是受益!謝謝~  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2011-04-10 08:48 我匿名可以么?

    寫的確實(shí)好!!!!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2011-05-11 14:49 onlyboor

    很適合新手。。。。感謝樓主。。。  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2011-07-12 17:28 fsdf

    很好,很強(qiáng)大  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2011-07-21 11:08 gameover

    專門過(guò)來(lái)感謝的。。。寫的很好..繼續(xù)完成剩下的任務(wù)  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2011-07-21 17:03 smshen

    很好,很強(qiáng)大,不過(guò)現(xiàn)在又發(fā)現(xiàn)自己對(duì)反射機(jī)制不太了解,學(xué)習(xí)中  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2011-09-24 02:54 roger

    文章果然不錯(cuò)!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2011-10-29 20:00 aaa

    不錯(cuò)哦  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2012-03-16 16:34 許齊

    HelloProxy 類的構(gòu)造 怎么是IHello啊 是不是錯(cuò)了  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2012-04-11 15:34 Steven

    我平時(shí)都是光看不回的,看到樓主的帖子,如茅塞頓開(kāi),我都忍不住給個(gè)好評(píng)了!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2012-04-26 22:00 John

    geilivable  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2012-05-03 11:46 張三

    很好,很強(qiáng)大!!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2012-06-02 21:27 helloword

    樓主,前面部分都不錯(cuò),我覺(jué)得沒(méi)什么問(wèn)題。
    但是最后一個(gè)示例我覺(jué)得有問(wèn)題  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2012-09-27 22:00 ermao

    你好,請(qǐng)問(wèn)為什么會(huì)出現(xiàn)線程問(wèn)題?  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2012-12-07 14:38 Eric

    頂!!! 講的不錯(cuò)  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2013-03-03 23:02 wcp

    我很好奇,例子里最簡(jiǎn)單的AOP用的應(yīng)該也算是裝飾器模式吧?  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2013-03-19 10:25 受教了

    NB,寫的太詳細(xì)透徹了。但是就是不知道線程問(wèn)題怎么來(lái)的。  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2013-04-19 16:35 yaogl

    大神級(jí)別的總結(jié)啊。。受益啦  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2013-07-19 11:28 www.dsprint.cn(武漢印刷)

    思路很清晰。頂!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2013-09-26 15:26 luinnx

    樓主思路清晰,對(duì)AOP更加了解了。樓主辛苦啦!~  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2013-11-27 18:03 Jacoh

    +1000  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2014-01-24 14:51 4

    020  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2014-04-15 10:31 qr

    很好的文章啊,很不錯(cuò)  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2014-04-15 10:32 qr

    看了好幾遍,對(duì)理解AOP很有幫助 thankyou  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2014-04-24 09:11 seven

    并沒(méi)有線程問(wèn)題,仔細(xì)看程序,實(shí)際上是logger寫錯(cuò)了。start打印了end,end方法打印了start @受教了
      回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2014-09-10 00:35 aa

    24 public Object bind(Object delegate,Object proxy) {
    25
    26 this.proxy = proxy;
    27 this.delegate = delegate;
    28 return Proxy.newProxyInstance(
    29 this.delegate.getClass().getClassLoader(), this.delegate
    30 .getClass().getInterfaces(), this);
    31 }
    好像是這樣的吧:
    public Object bind(Object delegate,Object proxy) {

    this.proxy = proxy;
    this.delegate = delegate;
    return Proxy.newProxyInstance(
    delegate.delegate.getClass().getClassLoader(),
    delegate.delegate .getClass().getInterfaces(),
    this);
    }  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2014-09-10 00:37 aa

    感覺(jué)是我錯(cuò)了,學(xué)習(xí)了  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2015-03-02 11:45 asdf

    講的很好  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理)[未登錄](méi) 2015-05-25 22:12 allen

    講的太好了!終于把動(dòng)態(tài)代理弄明白了。在看代理模式的時(shí)候碰到了動(dòng)態(tài)代理,然后動(dòng)態(tài)代理呢有想到了AOP,然后轉(zhuǎn)到這里來(lái)了。贊嘆!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2015-09-24 14:19 12

    很好  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2016-01-07 10:42 skyfall

    看了幾個(gè)人寫的東西,就看懂你說(shuō)的了,萬(wàn)分感謝!!  回復(fù)  更多評(píng)論   

    # re: 反射實(shí)現(xiàn) AOP 動(dòng)態(tài)代理模式(Spring AOP 的實(shí)現(xiàn) 原理) 2016-07-22 20:34 李文峰

    樓主寫得好棒  回復(fù)  更多評(píng)論   


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    <2008年3月>
    2425262728291
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(2)

    隨筆分類

    隨筆檔案

    文章檔案

    搜索

    最新評(píng)論

    主站蜘蛛池模板: 久久这里只精品国产免费10| 亚洲国产精品久久久久网站| 免费国产高清毛不卡片基地| 国产精品免费视频网站| 亚洲日韩国产欧美一区二区三区 | 男人的天堂亚洲一区二区三区| 色在线亚洲视频www| 在人线av无码免费高潮喷水| 亚洲另类春色国产精品| 日本zzzzwww大片免费| 亚洲国产夜色在线观看| 免费下载成人电影| 亚洲一区二区三区高清不卡| 免费无码又爽又刺激聊天APP| 亚洲日韩AV一区二区三区中文 | 一级毛片全部免费播放| 亚洲视频在线观看网站| 无码国产精品一区二区免费式影视 | 亚洲片国产一区一级在线观看| www一区二区www免费| 亚洲伊人久久大香线蕉综合图片| a毛片免费播放全部完整| 亚洲av无码不卡| 亚洲成人在线免费观看| 亚洲专区一路线二| 在线jlzzjlzz免费播放| 在线观看亚洲免费| 亚洲视频在线免费| 精品国产麻豆免费人成网站| 亚洲五月六月丁香激情| 日韩精品福利片午夜免费观着| 亚洲国产精品无码中文lv| 亚洲精品无码久久不卡| a毛片免费在线观看| 久久亚洲精品成人无码网站| 中文字幕影片免费在线观看| 国产亚洲欧美日韩亚洲中文色| 亚洲男人天堂2020| 免费无码av片在线观看| 亚洲老熟女@TubeumTV| 国内外成人免费视频|