spring注入方式注意:local/bean区别

<ref bean="someBean"/>
Specifying the target bean by using the bean attribute of the 
<ref/> tag is the most general form, and will allow creating a reference to any bean in the same container (whether or not in the same XML file), or parent container. The value of the 'bean' attribute may be the same as either the 'id' attribute of the target bean, or one of the values in the 'name' attribute of the target bean.
用“bean”属性指定目标bean是最常规的形式,这允许创建索引到任何同一容器内的bean(无论是否在同一XML文件中)或者父级的容器内的bean。“bean”属性的值可以和目标bean的“id”属性相同,也可以和目标bean的“name”属性内的一个值相同。

<ref local="someBean"/>
Specifying the target bean by using the local attribute leverages the ability of the XML parser to validate XML id references within the same file. The value of the local attribute must be the same as the id attribute of the target bean. The XML parser will issue an error if no matching element is found in the same file. As such, using the local variant is the best choice (in order to know about errors are early as possible) if the target bean is in the same XML file.
用“local”属性指定目标其实是指向同一文件内对应“id”属性值为此“local”值的索引。(这句比较难翻译,征集更好的翻译)
“local”属性的值必须和目标bean的id属性值相同。如果同一文件内没有匹配的元素,XML解析器将提示错误。同样,如果目标bean在同一XML文件内,使用“local”变量是最好的选择(为了尽可能早地知道错误)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值