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

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

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

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
    1、使用<context:annotation-config />簡化配置 
          Spring2.1添加了一個新的context的Schema命名空間,該命名空間對注釋驅動、屬性文件引入、加載期織入等功能提供了便捷的配置。我們知道注釋本身是不會做任何事情的,它僅提供元數據信息。要使元數據信息真正起作用,必須讓負責處理這些元數據的處理器工作起來。 
          AutowiredAnnotationBeanPostProcessor和CommonAnnotationBeanPostProcessor就是處理這些注釋元數據的處理器。但是直接在Spring配置文件中定義這些Bean顯得比較笨拙。Spring為我們提供了一種方便的注冊這些BeanPostProcessor的方式,這就是<context:annotation-config />:
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
        xsi:schemaLocation="http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">  
        <context:annotation-config />  
    </beans>  

    <context:annotationconfig />將隱式地向Spring容器注冊AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、 PersistenceAnnotationBeanPostProcessor以及RequiredAnnotationBeanPostProcessor這4個BeanPostProcessor。

    2、使用<context:component-scan />讓Bean定義注解工作起來
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
        xsi:schemaLocation="http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">  
        <context:component-scan base-package="com.kedacom.ksoa" />  
    </beans>  

    這里,所有通過<bean>元素定義Bean的配置內容已經被移除,僅需要添加一行<context:component-scan />配置就解決所有問題了——Spring XML配置文件得到了極致的簡化(當然配置元數據還是需要的,只不過以注釋形式存在罷了)。<context:component-scan />的base-package屬性指定了需要掃描的類包,類包及其遞歸子包中所有的類都會被處理。 
    < context:component-scan />還允許定義過濾器將基包下的某些類納入或排除。Spring支持以下4種類型的過濾方式: 
    過濾器類型 表達式范例 說明
    注解 org.example.SomeAnnotation將所有使用SomeAnnotation注解的類過濾出來
    類名指定 org.example.SomeClass過濾指定的類
    正則表達式 com\.kedacom\.spring\.annotation\.web\..*通過正則表達式過濾一些類
    AspectJ表達式 org.example..*Service+通過AspectJ表達式過濾一些類


    以正則表達式為例,我列舉一個應用實例:
    <context:component-scan base-package="com.casheen.spring.annotation">  
        <context:exclude-filter type="regex" expression="com\.casheen\.spring\.annotation\.web\..*" />  
    </context:component-scan>  

    值得注意的是<context:component-scan />配置項不但啟用了對類包進行掃描以實施注釋驅動Bean定義的功能,同時還啟用了注釋驅動自動注入的功能(即還隱式地在內部注冊了AutowiredAnnotationBeanPostProcessor和CommonAnnotationBeanPostProcessor),因此當使用<context:component-scan />后,就可以將<context:annotation-config />移除了.

    posted on 2015-03-23 19:38 abin 閱讀(404) 評論(0)  編輯  收藏 所屬分類: spring
    主站蜘蛛池模板: 亚洲视频在线观看网站| 中文在线观看免费网站| 亚洲一级毛片免费看| 亚洲AⅤ无码一区二区三区在线 | 亚洲 欧洲 视频 伦小说| 国产成人免费高清激情明星| 亚洲福利视频网址| 久久一区二区三区免费播放 | 亚洲av无码一区二区三区人妖 | 亚洲最新视频在线观看| 日本免费电影一区二区| 亚洲AV无码一区二区乱孑伦AS| a色毛片免费视频| 亚洲日本在线观看| 69国产精品视频免费| 亚洲人成片在线观看| 在线观看免费a∨网站| 亚洲精品无码久久久久A片苍井空 亚洲精品无码久久久久YW | 久久精品国产96精品亚洲| 久久精品一区二区免费看| 亚洲免费观看网站| 国产男女猛烈无遮档免费视频网站 | 一级毛片免费观看不卡视频| 亚洲最大成人网色| 性盈盈影院免费视频观看在线一区| 亚洲aⅴ天堂av天堂无码麻豆| 四虎成人精品一区二区免费网站| 亚洲色一区二区三区四区 | 成年在线网站免费观看无广告| 在线亚洲午夜片AV大片| 啊灬啊灬别停啊灬用力啊免费看| 日韩在线一区二区三区免费视频| 亚洲s色大片在线观看| 无码人妻精品一二三区免费| 九九免费观看全部免费视频| 国产亚洲av片在线观看播放| 免费观看美女用震蛋喷水的视频| 国产精品亚洲专一区二区三区| 中文字幕亚洲综合久久菠萝蜜| 性xxxx视频免费播放直播| 久久精品国产亚洲AV天海翼|