zyskm用夢想丈量人生,用奔跑丈量激情

          導航

          <2012年4月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          統計

          公告

          zyskm,zys是鄭勇勝的拼音簡寫,km公里的意思。
          以前曾跑過一段時間馬拉松,知道了這句名言“用夢想丈量人生,用奔跑丈量激情”,丈量的單位用公里km。

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          spring3系列 二、Spring配置項解釋說明

          這篇也是轉載,改了中間部分內。

          在基于注解方式配置
          Spring的配置文件中,你可能會見到<context:annotation-config/>這樣一條配置,他的作用是式地向 Spring 容器注冊

          AutowiredAnnotationBeanPostProcessorCommonAnnotationBeanPostProcessor、

          PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor  4 BeanPostProcessor。

          注冊這4 BeanPostProcessor的作用,就是為了你的系統能夠識別相應的注解。

          例如:

          如果你想使用@Autowired注解,那么就必須事先在 Spring 容器中聲明 AutowiredAnnotationBeanPostProcessor Bean。傳統聲明方式如下:

          1. <bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProcessor "/> 

          如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必須聲明CommonAnnotationBeanPostProcessor

          如果想使用@PersistenceContext注解,就必須聲明PersistenceAnnotationBeanPostProcessorBean

          如果想使用 @Required的注解,就必須聲明RequiredAnnotationBeanPostProcessorBean。同樣,傳統的聲明方式如下:

          1. <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/> 

          一般來說,這些注解我們還是比較常用,尤其是Antowired的注解,在自動注入的時候更是經常使用,所以如果總是需要按照傳統的方式一條一條配置顯得有些繁瑣和沒有必要,于是spring給我們提供<context:annotation-config/>的簡化配置方式,自動幫你完成聲明。

             不過,呵呵,我們使用注解一般都會配置掃描包路徑選項

          1. <context:component-scan base-package=”XX.XX”/> 

              該配置項其實也包含了自動注入上述processor的功能,因此當使用 <context:component-scan/> 后,就可以將 <context:annotation-config/> 移除了。

          本文轉載:http://mushiqianmeng.blog.51cto.com/3970029/723880

          posted on 2012-04-13 15:14 zyskm 閱讀(2575) 評論(4)  編輯  收藏

          評論

          # re: spring3系列 二、Spring配置項解釋說明 2012-04-13 15:50 周轉箱模具

          博客越來越少了……博主你一定要頂住??!我支持你!  回復  更多評論   

          # re: spring3系列 二、Spring配置項解釋說明 2012-04-25 17:00 路人甲

          樓主,你知道spring怎么配置或者怎么實現,在使用serviceBean的時候,只需要在action里建一個serviceBean的屬性,就可以直接使用,而不用通過spring的bean工廠去getBean(“xxx”),如下代碼

          。。。

          private UserInfoManagement userInfoManagement;

          public String loginSys(){
          UUserInfo user = userInfoManagement.getUserByName(username);

          。。。  回復  更多評論   

          # re: spring3系列 二、Spring配置項解釋說明 2012-04-26 16:10 zyskm

          自動裝配一共兩種方式實現:
          1.在xml顯示配置;
          2.通過注解方式實現,如在serviceBean增加@Service("xxxServiceBean"),在action中就可以實現自動裝配。@Component("xxxServiceBean")也可以,@service更準確些。@路人甲
            回復  更多評論   

          # re: spring3系列 二、Spring配置項解釋說明 2012-05-23 13:29 瘦腿精油

          Spring很強大  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 丹阳市| 余干县| 云林县| 聂拉木县| 通渭县| 东乡族自治县| 马边| 乐陵市| 故城县| 重庆市| 阳原县| 呼玛县| 成都市| 丁青县| 务川| 漾濞| 平利县| 噶尔县| 石屏县| 布拖县| 四会市| 南郑县| 双桥区| 宜宾市| 临桂县| 青冈县| 贵南县| 威远县| 建平县| 山丹县| 普定县| 阜新市| 化隆| 射阳县| 财经| 武义县| 灵川县| 游戏| 抚顺市| 西林县| 蒲城县|