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

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

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

    Atea - Hero's Grave

    面向?qū)ο螅_源,框架,敏捷,云計(jì)算,NoSQL,商業(yè)智能,編程思想。

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

    需要的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 閱讀(1994) 評(píng)論(0)  編輯  收藏 所屬分類: Spring
    主站蜘蛛池模板: 一个人看的www免费在线视频| 亚洲电影中文字幕| 国产精品网站在线观看免费传媒| 成人特黄a级毛片免费视频| 亚洲国产精品自在线一区二区| 在线看片免费人成视频久网下载| 亚洲国产综合精品中文字幕| 亚洲精品无码永久在线观看| 美女羞羞视频免费网站| 免费一级e一片在线播放| 国产精品自拍亚洲| 亚洲AV之男人的天堂| 久久高潮一级毛片免费| 亚洲精品乱码久久久久久| 爽爽爽爽爽爽爽成人免费观看| 国产亚洲一区二区三区在线观看| 今天免费中文字幕视频| 久热综合在线亚洲精品| 1000部禁片黄的免费看| 亚洲国产最大av| 一个人看的免费视频www在线高清动漫| 四虎永久免费影院| 中文字幕乱理片免费完整的| 亚洲国产精品无码久久久秋霞2| 99久热只有精品视频免费看| 亚洲依依成人精品| 国产免费黄色大片| 青柠影视在线观看免费| 亚洲国产夜色在线观看| 免费黄网在线观看| 亚洲一区二区电影| a级毛片在线免费观看| 久久精品国产亚洲AV香蕉| 女人毛片a级大学毛片免费| 无码的免费不卡毛片视频| 亚洲av之男人的天堂网站| 免费av欧美国产在钱| japanese色国产在线看免费| 亚洲午夜免费视频| 国产一卡二卡≡卡四卡免费乱码| 国产在线国偷精品免费看|