Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
431ca931
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
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,体验更适合开发者的 AI 搜索 >>
提交
431ca931
编写于
3月 18, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Leniently allow constructor argument matches if required name is not resolvable
Issue: SPR-13987
上级
455bf45f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
14 addition
and
8 deletion
+14
-8
spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
...ework/beans/factory/config/ConstructorArgumentValues.java
+6
-6
spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java
...gframework/beans/factory/support/ConstructorResolver.java
+1
-1
spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
...pringframework/beans/factory/xml/XmlBeanFactoryTests.java
+3
-1
spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml
.../beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml
+4
-0
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
浏览文件 @
431ca931
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -156,7 +156,7 @@ public class ConstructorArgumentValues {
* @param requiredType the type to match (can be {@code null} to match
* untyped values only)
* @param requiredName the type to match (can be {@code null} to match
* unnamed values only)
* unnamed values only
, or empty String to match any name
)
* @return the ValueHolder for the argument, or {@code null} if none set
*/
public
ValueHolder
getIndexedArgumentValue
(
int
index
,
Class
<?>
requiredType
,
String
requiredName
)
{
...
...
@@ -165,7 +165,7 @@ public class ConstructorArgumentValues {
if
(
valueHolder
!=
null
&&
(
valueHolder
.
getType
()
==
null
||
(
requiredType
!=
null
&&
ClassUtils
.
matchesTypeName
(
requiredType
,
valueHolder
.
getType
())))
&&
(
valueHolder
.
getName
()
==
null
||
(
valueHolder
.
getName
()
==
null
||
""
.
equals
(
requiredName
)
||
(
requiredName
!=
null
&&
requiredName
.
equals
(
valueHolder
.
getName
()))))
{
return
valueHolder
;
}
...
...
@@ -268,7 +268,7 @@ public class ConstructorArgumentValues {
* @param requiredType the type to match (can be {@code null} to find
* an arbitrary next generic argument value)
* @param requiredName the name to match (can be {@code null} to not
* match argument values by name)
* match argument values by name
, or empty String to match any 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} if none found
...
...
@@ -278,7 +278,7 @@ public class ConstructorArgumentValues {
if
(
usedValueHolders
!=
null
&&
usedValueHolders
.
contains
(
valueHolder
))
{
continue
;
}
if
(
valueHolder
.
getName
()
!=
null
&&
if
(
valueHolder
.
getName
()
!=
null
&&
!
""
.
equals
(
requiredName
)
&&
(
requiredName
==
null
||
!
valueHolder
.
getName
().
equals
(
requiredName
)))
{
continue
;
}
...
...
@@ -335,7 +335,7 @@ public class ConstructorArgumentValues {
* @param requiredType the parameter type to match (can be {@code null}
* to find an untyped argument value)
* @param requiredName the parameter name to match (can be {@code null}
* to find an unnamed argument value)
* to find an unnamed argument value
, or empty String to match any 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 (allowing to return the next generic argument match
...
...
spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java
浏览文件 @
431ca931
...
...
@@ -675,7 +675,7 @@ class ConstructorResolver {
for
(
int
paramIndex
=
0
;
paramIndex
<
paramTypes
.
length
;
paramIndex
++)
{
Class
<?>
paramType
=
paramTypes
[
paramIndex
];
String
paramName
=
(
paramNames
!=
null
?
paramNames
[
paramIndex
]
:
null
);
String
paramName
=
(
paramNames
!=
null
?
paramNames
[
paramIndex
]
:
""
);
// Try to find matching constructor argument value, either indexed or generic.
ConstructorArgumentValues
.
ValueHolder
valueHolder
=
resolvedValues
.
getArgumentValue
(
paramIndex
,
paramType
,
paramName
,
usedValueHolders
);
...
...
spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
浏览文件 @
431ca931
...
...
@@ -1612,12 +1612,14 @@ public class XmlBeanFactoryTests {
assertEquals
(
0
,
((
String
[])
bean
.
array
).
length
);
}
@Test
@Ignore
// TODO: SPR-13987
@Test
public
void
testConstructorWithUnresolvableParameterName
()
{
DefaultListableBeanFactory
xbf
=
new
DefaultListableBeanFactory
();
new
XmlBeanDefinitionReader
(
xbf
).
loadBeanDefinitions
(
CONSTRUCTOR_ARG_CONTEXT
);
AtomicInteger
bean
=
(
AtomicInteger
)
xbf
.
getBean
(
"constructorUnresolvableName"
);
assertEquals
(
1
,
bean
.
get
());
bean
=
(
AtomicInteger
)
xbf
.
getBean
(
"constructorUnresolvableNameWithIndex"
);
assertEquals
(
1
,
bean
.
get
());
}
@Test
...
...
spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml
浏览文件 @
431ca931
...
...
@@ -231,4 +231,8 @@
<constructor-arg
name=
"initialValue"
value=
"1"
/>
</bean>
<bean
id=
"constructorUnresolvableNameWithIndex"
class=
"java.util.concurrent.atomic.AtomicInteger"
scope=
"prototype"
>
<constructor-arg
index=
"0"
name=
"initialValue"
value=
"1"
/>
</bean>
</beans>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录