紙飛機

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

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

             <
          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 解析器就會產生一個 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 方式,開發者能夠使用到 XML 本身提供 的優勢,而進行驗證。
          3)parent:
          用于指定其依賴的父 JavaBean 定義。

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

          評論

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

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

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

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

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

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


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


          網站導航:
           
          主站蜘蛛池模板: 新津县| 长顺县| 荣昌县| 宾阳县| 老河口市| 延寿县| 射洪县| 浦城县| 雷州市| 亚东县| 双鸭山市| 万年县| 奉新县| 犍为县| 姜堰市| 合肥市| 赣榆县| 上饶市| 巴里| 寿宁县| 包头市| 黎城县| 宁都县| 乌拉特中旗| 天全县| 龙南县| 融水| 阳新县| 韶关市| 邢台县| 兴义市| 新巴尔虎左旗| 宜君县| 原平市| 上林县| 襄垣县| 洮南市| 蛟河市| 焦作市| 自贡市| 儋州市|