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

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

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

    Atea - Hero's Grave

    面向對象,開源,框架,敏捷,云計算,NoSQL,商業智能,編程思想。

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      40 隨筆 :: 0 文章 :: 28 評論 :: 0 Trackbacks
    網上沒找到符合需求的資料,前后鼓搗了兩天才弄好。
    《Spring in Action》中的aop例子-吟游詩人(Minstrel)雖然生動,但代碼不全,可害苦我了:<
    后又結合spring reference 6.2節看了半天,才琢麼出來。

    需要的jar文件:
    spring.jar
    commons-logging.jar
    aspectjrt.jar
    aspectjweaver.jar
    cglib-nodep.jar
    asm.jar
    asm-commons.jar

    spring config file: helloworld.xml
        <bean id="firsttest" class="firsttest.Firsttest">
            
    <property name="name" value="Atea" />
        
    </bean>
        
        
    <!--aop bean-->
        
    <bean id="firsttest_AOP" class="firsttest.Firsttest_AOP" />
        
    <aop:config>
            
    <aop:aspect ref="firsttest_AOP">         
                
    <!--無參aop-->
                
    <aop:pointcut id="apc1" expression="execution(* aopTest())" />
                
    <aop:before pointcut-ref="apc1" method="whoSayHello" />
                
                
    <!--帶參aop-->
                
    <aop:pointcut id="apc2" expression="execution(* aopTest(firsttest.Firsttest))"/>
                
    <aop:after-returning  pointcut-ref="apc2" method="whoSayHello(firsttest.Firsttest)" returning="ft" />
            
    </aop:aspect>        
        
    </aop:config>

    Firsttest.java
    package firsttest;
    public class Firsttest {   
        
        
    private String name;   
        
    //getter and setter..       
     
        
    public void aopTest(){
            System.out.println(
    "aopTest");
        }
        
    public Firsttest aopTest(Firsttest ft){
            System.out.println(
    "aopTest param");
            
    return ft;
        }  
    }

    Firsttest_AOP.java
    package firsttest;
    public class Firsttest_AOP {

        
    public void whoSayHello(Firsttest ft){
            System.out.println(ft.getName() 
    + " said hello!");
        } 
        
        
    public void whoSayHello(){
            System.out.println(
    "who said hello?");
        }

    }

    MyTest.java
    import org.junit.Test;
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    public class MyTest {
        @Test
        
    public void hello() {
            BeanFactory factory 
    = new ClassPathXmlApplicationContext("helloworld.xml");
            Firsttest ft 
    = (Firsttest)factory.getBean("firsttest");
            ft.aopTest();
            ft.aopTest(ft);
        }
    }

    run result:
    who said hello?
    aopTest
    aopTest param
    Atea said hello
    !

    posted on 2008-08-18 16:52 Atea 閱讀(1987) 評論(0)  編輯  收藏 所屬分類: Spring
    主站蜘蛛池模板: 无码午夜成人1000部免费视频| 国产精品玖玖美女张开腿让男人桶爽免费看 | 中文字幕在线视频免费| 青青青国产色视频在线观看国产亚洲欧洲国产综合 | 九九99热免费最新版| 国产亚洲一区区二区在线| 国产免费内射又粗又爽密桃视频| 毛茸茸bbw亚洲人| 中文字幕无线码中文字幕免费| 亚洲成AV人片在WWW色猫咪| 国产午夜免费高清久久影院| 亚洲一区二区三区首页| jjizz全部免费看片| 亚洲人成77777在线播放网站不卡| 四色在线精品免费观看| 精品在线观看免费| 国产成人亚洲综合无码| 免费观看在线禁片| 亚洲中文字幕在线无码一区二区| 成年女人18级毛片毛片免费观看| 亚洲AV成人无码网天堂| 久久精品国产亚洲Aⅴ香蕉| 日本在线免费播放| 日韩亚洲国产高清免费视频| 无码欧精品亚洲日韩一区夜夜嗨| 黄视频在线观看免费| 亚洲天天在线日亚洲洲精| 噼里啪啦电影在线观看免费高清| 亚洲国产午夜精品理论片在线播放| 亚洲AV无码乱码在线观看| 最近免费mv在线观看动漫| 亚洲午夜精品一区二区公牛电影院| 日本免费一二区在线电影| 韩国免费A级毛片久久| 亚洲三级在线播放| 亚洲精品国产自在久久| 青青青免费国产在线视频小草| 精品视频免费在线| 亚洲另类精品xxxx人妖| 精品亚洲一区二区三区在线播放| 特级精品毛片免费观看|