紙飛機

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            22 隨筆 :: 28 文章 :: 30 評論 :: 0 Trackbacks

          今天在做SSH框架Demo實例時,在ApplicationResources.properties文件時對<ref bean>與<ref local>感到不解,經(jīng)查找資料才弄明白,如下:

             <
          bean id = "userDAOProxy"

                  class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >

                  < property name = "transactionManager" >

                      < ref bean = "transactionManager" />

                  </ property >

                  < property name = "target" >

                      < ref local = "UserDAO" />

                  </ property >

              </ bean >

          1 、用 local 屬性指定目標 bean 可以利用 xml 解析器的能力在同一個文件中驗證 xml id 引用 . 如果在同一個文件中沒有匹 配的元素 ,xml 解析器就會產(chǎn)生一個 error, 所以如果目標 bean 在同一個 xml 文件中 , 那么用 local 形式是最好的選擇 .


          2
          、可以這么說, <ref bean 是尋找全局中的 bean; <ref local 是尋找本 xml 文件中的 bean


          3 <ref> 提供了如下幾方面的屬性 :
          1)bean:
          在當前 Spring XML 配置文件中,或者在同一 BeanFactory(ApplicationContext) 中的其他 JavaBean .
          2)local:
          在當前 Spring XML 配置文件中 . 其依賴的 JavaBean 必須存在于當前 Spring XML 培植文件中 . 如果借助 于 Spring IDE, 則在編譯期可以對其依賴的 JavaBean 進行驗證。基于 local 方式,開發(fā)者能夠使用到 XML 本身提供 的優(yōu)勢,而進行驗證。
          3)parent:
          用于指定其依賴的父 JavaBean 定義。

          posted on 2007-01-20 01:54 紙飛機 閱讀(13249) 評論(6)  編輯  收藏

          評論

          # re: Spring中ref local與ref bean區(qū)別:[未登錄] 2008-09-19 16:12 liu
          good
            回復  更多評論
            

          # re: Spring中ref local與ref bean區(qū)別:[未登錄] 2009-05-19 18:53 aaa
          xiexie  回復  更多評論
            

          # re: Spring中ref local與ref bean區(qū)別: 2009-08-21 11:33 yawaking
          謝謝  回復  更多評論
            

          # re: Spring中ref local與ref bean區(qū)別: 2011-12-29 11:00 chenxinhu
          謝謝了,非常感謝  回復  更多評論
            

          # re: Spring中ref local與ref bean區(qū)別: 2012-08-01 00:20 王鵬飛
          知道了,哦。有一個spring配置文件的話,用local就可以了  回復  更多評論
            

          # re: Spring中ref local與ref bean區(qū)別: 2012-11-01 15:50 sim
          了解,謝謝~~  回復  更多評論
            


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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 延吉市| 尉氏县| 循化| 旺苍县| 昭平县| 靖宇县| 芒康县| 天津市| 阿鲁科尔沁旗| 眉山市| 淄博市| 漯河市| 朝阳县| 宽城| 湄潭县| 东乡县| 怀安县| 兴文县| 鄂伦春自治旗| 长泰县| 兰坪| 梧州市| 江源县| 桐梓县| 乌鲁木齐市| 镇远县| 天津市| 乐清市| 祁东县| 沙湾县| 建平县| 南康市| 邓州市| 云安县| 壤塘县| 万州区| 巴南区| 咸丰县| 浮梁县| 苏尼特左旗| 顺昌县|