<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
    主站蜘蛛池模板: 色婷婷亚洲一区二区三区| 亚洲男人电影天堂| 激情吃奶吻胸免费视频xxxx| 免费国产黄线在线观看| 亚洲国产精品网站久久| 黄页网站免费在线观看| 无码免费一区二区三区免费播放| 在线观看特色大片免费视频| 国产成人免费片在线观看| 国产亚洲精品影视在线| 丁香花在线视频观看免费| 中文亚洲AV片在线观看不卡| 东北美女野外bbwbbw免费| 亚洲V无码一区二区三区四区观看| 亚洲人成色在线观看| 暖暖在线日本免费中文| 国产亚洲午夜精品| 97无码免费人妻超级碰碰碰碰| 亚洲熟妇久久精品| 1000部拍拍拍18勿入免费凤凰福利| 911精品国产亚洲日本美国韩国 | 亚洲精品偷拍视频免费观看| 亚洲伊人tv综合网色| 午夜性色一区二区三区免费不卡视频 | 永久免费在线观看视频| 日韩一卡2卡3卡4卡新区亚洲 | 免费不卡视频一卡二卡| 亚洲成a人无码亚洲成av无码| 亚洲国产精品无码久久九九| 波多野结衣亚洲一级| 青青草国产免费久久久下载| eeuss影院ss奇兵免费com| 久久综合亚洲色一区二区三区 | 国产免费一区二区三区VR| 久久性生大片免费观看性| 久久久亚洲裙底偷窥综合| 国产国产人免费人成免费视频| 不卡视频免费在线观看| 亚洲欧美日韩中文高清www777| 亚洲精品无码乱码成人| 女人张腿给男人桶视频免费版|