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

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

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

    laoding
    本來我以為,隱身了別人就找不到我,沒有用的,像我這樣拉風的男人,無論走到哪里,都像在黑暗中的螢火蟲一樣,那樣的鮮明,那樣的出眾。我那憂郁的眼神,稀疏的胡茬,那微微隆起的將軍肚和親切的笑容......都深深吸引了眾人......
    posts - 0,  comments - 37,  trackbacks - 0
    上一篇中用XMLSchema配置方式介紹了簡單日志實現,這里再用annotation來介紹(注意是spring2.0)

    來看接口,這個接口簡單的不能再簡單了,嘻嘻。
    public interface Hello {
        String hello(String name);
    }

    實現類:

    public class SayHello implements Hello {

        
    public String hello(String name) {
            String result 
    = "---hello " + name;
            System.out.println(result);
            
    return result;
        }

    }

    切面,里面采用了annotation來注釋,也說明了大概意思:

    /* 
     * Create Date:2008-11-20 下午03:09:11
     * 
     * Author:dingkm
     * 
     * Version: V1.0
     * 
     * Description:對進行修改的功能進行描述 
     * 
     *  
     
    */
    //首先這是注釋這個類就是切面
    @Aspect
    public class MyAspect {
        
    //這里是注釋要切入的方法,AfterReturning是表示方法返回以后進行切入,我這里
        
    //選這個的話是因為日志一般都是在方法執行完成后記錄,當然你可以拿Before來試
        @AfterReturning("execution(* *.aspectJ.*.hello(..))")
        
    public void doLog(ProceedingJoinPoint joinpoint) throws Throwable{
            String result 
    = (String)joinpoint.proceed();
            System.out.println(
    "---doLog"+result);
        }
    }

    下面是spring配置文件,這里的配置文件就比較簡單了:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop
    ="http://www.springframework.org/schema/aop"
        xmlns:tx
    ="http://www.springframework.org/schema/tx"
        xmlns:jee
    ="http://www.springframework.org/schema/jee"
        xsi:schemaLocation
    ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd"
    >
        
        
    <!--基于@AspectJ切面的驅動器,如果沒有這句話  切面的代碼是不會執行的,可以試下--> 
        
    <aop:aspectj-autoproxy/>
        
        
    <!--這個bean是作為切面    -->
        
    <bean id="myAspect" class="spring2aop.aspectJ.MyAspect"></bean>
        
        
    <!--要織入代碼的bean-->
        
    <bean id="hello" class="spring2aop.aspectJ.SayHello"></bean>

    </beans>

    <aop:aspectj-autoproxy/>這句很關鍵哦

    再來看測試類:

    public class Test {

        
    /**  
         *   @Description 方法實現功能描述  
         *   
    @param args
         *   void
         *   
    @throws  拋出異常說明
         
    */
        
    public static void main(String[] args) {
            ApplicationContext act 
    = new ClassPathXmlApplicationContext(
            
    "applicationContext21.xml");
            Hello h 
    = (Hello)act.getBean("hello");
            h.hello(
    "laoding");
        }

    }

    看看結果:

    ---hello laoding
    ---hello laoding
    ---doLog---hello laoding

    ---hello laoding這個與上一篇文章中提到的道理一樣,因為記錄日志要取得返回結果,所以執行了兩次

    最后的那句就是我們要的,這樣就達到了記錄日志的目的,哈哈,收工回去看PPS中韓魔獸對抗。
    posted on 2008-11-25 18:27 老丁 閱讀(1729) 評論(0)  編輯  收藏 所屬分類: spring
    本博客主為學習和復習之用,無關其他,想罵人的繞道
    Email:dkm123456@126.com
    大家一起交流進步
    QQ:283582761


    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    留言簿(4)

    我參與的團隊

    文章分類(50)

    文章檔案(48)

    相冊

    朋友

    搜索

    •  

    積分與排名

    • 積分 - 96432
    • 排名 - 600

    最新評論

    主站蜘蛛池模板: 亚洲欧洲中文日韩久久AV乱码| 亚洲AV无码码潮喷在线观看| 国产免费内射又粗又爽密桃视频| 亚洲色精品88色婷婷七月丁香| 1000部无遮挡拍拍拍免费视频观看 | 亚洲jjzzjjzz在线观看| 国产免费黄色大片| 污污网站免费观看| 四虎影视永久在线精品免费| 亚洲成色在线综合网站 | 亚洲国产综合久久天堂| 日韩精品极品视频在线观看免费 | 四虎亚洲精品高清在线观看| 国产精品亚洲综合专区片高清久久久| 精品无码AV无码免费专区| 无忧传媒视频免费观看入口| 亚洲国产女人aaa毛片在线| 日本免费人成黄页在线观看视频| 青青操在线免费观看| 亚洲国产成人无码AV在线| 久久久久亚洲AV成人无码网站| 国产成人一区二区三区免费视频| 免费无码成人AV在线播放不卡| 黄页网站在线免费观看| 亚洲精品中文字幕无码AV| 伊人久久综在合线亚洲91| 韩国欧洲一级毛片免费 | 中文字幕亚洲不卡在线亚瑟| 欧美在线看片A免费观看| 麻豆精品不卡国产免费看| 午夜在线亚洲男人午在线| 亚洲一区二区三区深夜天堂| 亚洲人成人网站色www| 免费在线视频一区| 女人18毛片a级毛片免费视频| 可以免费观看的国产视频| 久久一区二区三区免费| 国产亚洲午夜精品| 亚洲乱色熟女一区二区三区蜜臀| 久久亚洲精品无码aⅴ大香| 亚洲av永久无码精品网站|