博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
value-ref, key-ref, ref local, ref bean
阅读量:6452 次
发布时间:2019-06-23

本文共 2010 字,大约阅读时间需要 6 分钟。

hot3.png

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 BeanFactory/ApplicationContext (whether or not in the same XML file), or parent BeanFactory/ApplicationContext. 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.

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.

This is from the Spring source reference 

value-ref, key-ref 则是面向map应用的。

The map element will create a java.util.Map that can be injected into a constructor or property. The map element expects an entry element inside it to define key/value pairs for theMap. There are a few different ways to create the entry element. One way is to have a value element, ref element, or bean element nested inside the key element for the key or inside the entry element for the value.

Creating beans this way is very verbose, but there are shortcut attributes on the entry element. The key attribute uses the attribute as a value and the key-ref uses the attribute value as a reference. Just like the ref attribute on the constructor-arg and property elements inside a bean definition, the key-ref attribute is equivalent to a ref element's bean attribute. There isn't a shortcut for the ref element's local attribute. There are also value and value-ref attributes with the same behavior as the key and key-ref attributes, but these obviously set the value for each entry.

转载于:https://my.oschina.net/u/138995/blog/187906

你可能感兴趣的文章
再次更新
查看>>
perl杂记
查看>>
go语言安装使用
查看>>
iOS开发代理(委托)模式详解
查看>>
微服务学习笔记二:Eureka服务注册发现
查看>>
C# 获取编码
查看>>
mysql的数据类型int、bigint、smallint 和 tinyint取值范围
查看>>
利用网易获取所有股票数据
查看>>
HDOJ5015 233 Matrix(矩阵乘法加速递推)
查看>>
移动铁通宽带上网设置教程
查看>>
java中判断字符串中是否有中文字符
查看>>
Python算法(含源代码下载)
查看>>
利用Windows自带的Certutil查看文件MD5
查看>>
通过原生js添加div和css
查看>>
简单的导出表格和将表格下载到桌面上。
查看>>
《ArcGIS Engine+C#实例开发教程》第一讲桌面GIS应用程序框架的建立
查看>>
递归查询上一级
查看>>
JAVA - 大数类详解
查看>>
查询指定名称的文件
查看>>
批处理文件
查看>>