您的位置:首页 > 编程语言 > Java开发

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

2009-02-16 11:33 239 查看
<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”变量是最好的选择(为了尽可能早地知道错误)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: