纸飞机

  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 纸飞机 阅读(13191) 评论(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
了解,谢谢~~  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: