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

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

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

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

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

    實現(xiàn)類:

    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:對進(jìn)行修改的功能進(jìn)行描述 
     * 
     *  
     
    */
    //首先這是注釋這個類就是切面
    @Aspect
    public class MyAspect {
        
    //這里是注釋要切入的方法,AfterReturning是表示方法返回以后進(jìn)行切入,我這里
        
    //選這個的話是因為日志一般都是在方法執(zhí)行完成后記錄,當(dāng)然你可以拿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切面的驅(qū)動器,如果沒有這句話  切面的代碼是不會執(zhí)行的,可以試下--> 
        
    <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/>這句很關(guān)鍵哦

    再來看測試類:

    public class Test {

        
    /**  
         *   @Description 方法實現(xiàn)功能描述  
         *   
    @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");
        }

    }

    看看結(jié)果:

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

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

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


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

    留言簿(4)

    我參與的團(tuán)隊

    文章分類(50)

    文章檔案(48)

    相冊

    朋友

    搜索

    •  

    積分與排名

    • 積分 - 96446
    • 排名 - 600

    最新評論

    主站蜘蛛池模板: kk4kk免费视频毛片| 亚洲精品无码久久久久久| j8又粗又长又硬又爽免费视频| 成年性生交大片免费看 | 国产免费人成在线视频| 亚洲爆乳大丰满无码专区| 成年在线观看网站免费| 中文字幕乱码亚洲无线三区| 最近中文字幕无吗高清免费视频| 亚洲国产精品一区二区三区在线观看 | 亚洲精品你懂的在线观看| 热99RE久久精品这里都是精品免费| 亚洲精品少妇30p| 久久精品视频免费播放| 亚洲无人区视频大全| 国产成人无码免费看视频软件| 色在线亚洲视频www| 免费羞羞视频网站| 美女被暴羞羞免费视频| 亚洲国产主播精品极品网红| fc2免费人成在线| 超清首页国产亚洲丝袜| a毛片在线免费观看| 久久亚洲AV成人无码软件| 啦啦啦高清视频在线观看免费| 亚洲欧美日韩国产精品一区| 亚洲成a人片在线观看久| 福利免费在线观看| 亚洲av伊人久久综合密臀性色| 精品国产sm捆绑最大网免费站| 亚洲成a人片在线观看中文app| 女人18毛片水真多免费看| 精品在线免费视频| 久久久综合亚洲色一区二区三区| 国产va精品免费观看| 色婷婷综合缴情综免费观看| 亚洲精品无码乱码成人| 午夜影院免费观看| 亚洲欧美第一成人网站7777| 亚洲天堂免费在线视频| 免费人成在线观看网站品爱网|