Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
666700f7
S
spring-framework
项目概览
dk131072
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
666700f7
编写于
11月 30, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
constructor arguments can be overridden by name in child bean definitions (SPR-6463)
上级
cc323998
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
17 deletion
+50
-17
org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
...ework/beans/factory/config/ConstructorArgumentValues.java
+34
-11
org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml
.../beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml
+6
-1
org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
...pringframework/beans/factory/xml/XmlBeanFactoryTests.java
+10
-5
未找到文件。
org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
浏览文件 @
666700f7
...
...
@@ -76,7 +76,7 @@ public class ConstructorArgumentValues {
}
for
(
ValueHolder
valueHolder
:
other
.
genericArgumentValues
)
{
if
(!
this
.
genericArgumentValues
.
contains
(
valueHolder
))
{
this
.
genericArgumentValues
.
add
(
valueHolder
.
copy
());
addOrMergeGenericArgumentValue
(
valueHolder
.
copy
());
}
}
}
...
...
@@ -84,7 +84,7 @@ public class ConstructorArgumentValues {
/**
* Add argument value for the given index in the constructor argument list.
* Add a
n a
rgument value for the given index in the constructor argument list.
* @param index the index in the constructor argument list
* @param value the argument value
*/
...
...
@@ -93,7 +93,7 @@ public class ConstructorArgumentValues {
}
/**
* Add argument value for the given index in the constructor argument list.
* Add a
n a
rgument value for the given index in the constructor argument list.
* @param index the index in the constructor argument list
* @param value the argument value
* @param type the type of the constructor argument
...
...
@@ -103,7 +103,7 @@ public class ConstructorArgumentValues {
}
/**
* Add argument value for the given index in the constructor argument list.
* Add a
n a
rgument value for the given index in the constructor argument list.
* @param index the index in the constructor argument list
* @param newValue the argument value in the form of a ValueHolder
*/
...
...
@@ -114,7 +114,7 @@ public class ConstructorArgumentValues {
}
/**
* Add argument value for the given index in the constructor argument list,
* Add a
n a
rgument value for the given index in the constructor argument list,
* merging the new value (typically a collection) with the current value
* if demanded: see {@link org.springframework.beans.Mergeable}.
* @param key the index in the constructor argument list
...
...
@@ -183,7 +183,7 @@ public class ConstructorArgumentValues {
/**
* Add generic argument value to be matched by type.
* Add
a
generic argument value to be matched by type.
* <p>Note: A single generic argument value will just be used once,
* rather than matched multiple times.
* @param value the argument value
...
...
@@ -193,7 +193,7 @@ public class ConstructorArgumentValues {
}
/**
* Add generic argument value to be matched by type.
* Add
a
generic argument value to be matched by type.
* <p>Note: A single generic argument value will just be used once,
* rather than matched multiple times.
* @param value the argument value
...
...
@@ -204,7 +204,7 @@ public class ConstructorArgumentValues {
}
/**
* Add
generic argument value to be matched by type
.
* Add
a generic argument value to be matched by type or name (if available)
.
* <p>Note: A single generic argument value will just be used once,
* rather than matched multiple times.
* @param newValue the argument value in the form of a ValueHolder
...
...
@@ -215,10 +215,33 @@ public class ConstructorArgumentValues {
public
void
addGenericArgumentValue
(
ValueHolder
newValue
)
{
Assert
.
notNull
(
newValue
,
"ValueHolder must not be null"
);
if
(!
this
.
genericArgumentValues
.
contains
(
newValue
))
{
this
.
genericArgumentValues
.
add
(
newValue
);
addOrMergeGenericArgumentValue
(
newValue
);
}
}
/**
* Add a generic argument value, merging the new value (typically a collection)
* with the current value if demanded: see {@link org.springframework.beans.Mergeable}.
* @param newValue the argument value in the form of a ValueHolder
*/
private
void
addOrMergeGenericArgumentValue
(
ValueHolder
newValue
)
{
if
(
newValue
.
getName
()
!=
null
)
{
for
(
Iterator
<
ValueHolder
>
it
=
this
.
genericArgumentValues
.
iterator
();
it
.
hasNext
();)
{
ValueHolder
currentValue
=
it
.
next
();
if
(
newValue
.
getName
().
equals
(
currentValue
.
getName
()))
{
if
(
newValue
.
getValue
()
instanceof
Mergeable
)
{
Mergeable
mergeable
=
(
Mergeable
)
newValue
.
getValue
();
if
(
mergeable
.
isMergeEnabled
())
{
newValue
.
setValue
(
mergeable
.
merge
(
currentValue
.
getValue
()));
}
}
it
.
remove
();
}
}
}
this
.
genericArgumentValues
.
add
(
newValue
);
}
/**
* Look for a generic argument value that matches the given type.
* @param requiredType the type to match
...
...
@@ -244,8 +267,8 @@ public class ConstructorArgumentValues {
* resolution process.
* @param requiredType the type to match (can be <code>null</code> to find
* an arbitrary next generic argument value)
* @param requiredName the
type to match (can be <code>null</code> to match
*
unnamed values only
)
* @param requiredName the
name to match (can be <code>null</code> to not
*
match argument values by name
)
* @param usedValueHolders a Set of ValueHolder objects that have already been used
* in the current resolution process and should therefore not be returned again
* @return the ValueHolder for the argument, or <code>null</code> if none found
...
...
org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml
浏览文件 @
666700f7
...
...
@@ -109,7 +109,12 @@
<constructor-arg><value>
29
</value></constructor-arg>
</bean>
<bean
id=
"rod17"
class=
"org.springframework.beans.factory.xml.SimpleConstructorArgBean"
scope=
"prototype"
>
<bean
id=
"rod17"
parent=
"rod16"
>
<constructor-arg
name=
"otherSpouse"
><ref
bean=
"kerry2"
/></constructor-arg>
<constructor-arg
name=
"spouse"
><ref
bean=
"kerry1"
/></constructor-arg>
</bean>
<bean
id=
"rod18"
class=
"org.springframework.beans.factory.xml.SimpleConstructorArgBean"
scope=
"prototype"
>
</bean>
<bean
id=
"kerry1"
class=
"org.springframework.beans.TestBean"
>
...
...
org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
浏览文件 @
666700f7
...
...
@@ -955,19 +955,24 @@ public final class XmlBeanFactoryTests {
assertEquals
(
kerry2
,
rod16
.
getSpouse1
());
assertEquals
(
kerry1
,
rod16
.
getSpouse2
());
assertEquals
(
29
,
rod16
.
getAge
());
ConstructorDependenciesBean
rod17
=
(
ConstructorDependenciesBean
)
xbf
.
getBean
(
"rod17"
);
assertEquals
(
kerry1
,
rod17
.
getSpouse1
());
assertEquals
(
kerry2
,
rod17
.
getSpouse2
());
assertEquals
(
29
,
rod17
.
getAge
());
}
public
@Test
void
testPrototypeWithExplicitArguments
()
{
XmlBeanFactory
xbf
=
new
XmlBeanFactory
(
CONSTRUCTOR_ARG_CONTEXT
);
SimpleConstructorArgBean
cd1
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
7
"
);
SimpleConstructorArgBean
cd1
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
8
"
);
assertEquals
(
0
,
cd1
.
getAge
());
SimpleConstructorArgBean
cd2
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
7
"
,
98
);
SimpleConstructorArgBean
cd2
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
8
"
,
98
);
assertEquals
(
98
,
cd2
.
getAge
());
SimpleConstructorArgBean
cd3
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
7
"
,
"myName"
);
SimpleConstructorArgBean
cd3
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
8
"
,
"myName"
);
assertEquals
(
"myName"
,
cd3
.
getName
());
SimpleConstructorArgBean
cd4
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
7
"
);
SimpleConstructorArgBean
cd4
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
8
"
);
assertEquals
(
0
,
cd4
.
getAge
());
SimpleConstructorArgBean
cd5
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
7
"
,
97
);
SimpleConstructorArgBean
cd5
=
(
SimpleConstructorArgBean
)
xbf
.
getBean
(
"rod1
8
"
,
97
);
assertEquals
(
97
,
cd5
.
getAge
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录