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

    需要的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">         
                
    <!--無(wú)參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) 評(píng)論(0)  編輯  收藏 所屬分類: Spring
    主站蜘蛛池模板: 一级毛片试看60分钟免费播放| 成全高清在线观看免费| 7723日本高清完整版免费| 久久伊人亚洲AV无码网站| 一个人看的在线免费视频| 亚洲成a人片在线观看老师| 美女裸体无遮挡免费视频网站| 一区在线免费观看| 亚洲爽爽一区二区三区| 精品一区二区三区免费观看| 一级毛片直播亚洲| 妞干网在线免费视频| 亚洲AV成人影视在线观看| 好吊妞998视频免费观看在线| 国产日产亚洲系列最新| 丝袜捆绑调教视频免费区| 国产成人A人亚洲精品无码| 日本在线免费播放| 亚洲理论片在线观看| 成人免费无码大片a毛片软件| 亚洲成A人片在线观看无码不卡| 亚洲国产日韩综合久久精品| 日韩中文无码有码免费视频| 久久亚洲AV成人无码软件| 无码国产精品一区二区免费I6| 亚洲国产一级在线观看| 国产拍拍拍无码视频免费| 亚洲成A∨人片天堂网无码| 一级毛片无遮挡免费全部| 亚洲av永久无码精品古装片| 五月天婷婷精品免费视频| 亚洲AV无码精品色午夜在线观看| 深夜福利在线免费观看| 久久精品国产精品亚洲艾| 无码专区永久免费AV网站| 中文字幕免费在线播放| 亚洲激情视频图片| 国产精品亚洲w码日韩中文| 1000部免费啪啪十八未年禁止观看| 久久亚洲高清综合| 97人妻无码一区二区精品免费|