Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
9b25d6ad
S
spring-framework
项目概览
chenpeng_fei
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
9b25d6ad
编写于
3月 06, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
getTypeForFactoryBean suppresses instantiation failures for non-singleton FactoryBeans
Issue: SPR-12786
上级
0baf228d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
16 deletion
+43
-16
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
...s/factory/support/AbstractAutowireCapableBeanFactory.java
+8
-0
spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java
...mework/beans/factory/DefaultListableBeanFactoryTests.java
+35
-16
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
浏览文件 @
9b25d6ad
...
@@ -897,6 +897,14 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
...
@@ -897,6 +897,14 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
instance
=
bw
.
getWrappedInstance
();
instance
=
bw
.
getWrappedInstance
();
}
}
}
}
catch
(
BeanCreationException
ex
)
{
// Can only happen when getting a FactoryBean.
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Bean creation exception on non-singleton FactoryBean type check: "
+
ex
);
}
onSuppressedException
(
ex
);
return
null
;
}
finally
{
finally
{
// Finished partial creation of this bean.
// Finished partial creation of this bean.
afterPrototypeCreation
(
beanName
);
afterPrototypeCreation
(
beanName
);
...
...
spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java
浏览文件 @
9b25d6ad
/*
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -1340,10 +1340,10 @@ public class DefaultListableBeanFactoryTests {
...
@@ -1340,10 +1340,10 @@ public class DefaultListableBeanFactoryTests {
public
void
testDependsOnCycle
()
{
public
void
testDependsOnCycle
()
{
DefaultListableBeanFactory
lbf
=
new
DefaultListableBeanFactory
();
DefaultListableBeanFactory
lbf
=
new
DefaultListableBeanFactory
();
RootBeanDefinition
bd1
=
new
RootBeanDefinition
(
TestBean
.
class
);
RootBeanDefinition
bd1
=
new
RootBeanDefinition
(
TestBean
.
class
);
bd1
.
setDependsOn
(
new
String
[]
{
"tb2"
}
);
bd1
.
setDependsOn
(
"tb2"
);
lbf
.
registerBeanDefinition
(
"tb1"
,
bd1
);
lbf
.
registerBeanDefinition
(
"tb1"
,
bd1
);
RootBeanDefinition
bd2
=
new
RootBeanDefinition
(
TestBean
.
class
);
RootBeanDefinition
bd2
=
new
RootBeanDefinition
(
TestBean
.
class
);
bd2
.
setDependsOn
(
new
String
[]
{
"tb1"
}
);
bd2
.
setDependsOn
(
"tb1"
);
lbf
.
registerBeanDefinition
(
"tb2"
,
bd2
);
lbf
.
registerBeanDefinition
(
"tb2"
,
bd2
);
try
{
try
{
lbf
.
preInstantiateSingletons
();
lbf
.
preInstantiateSingletons
();
...
@@ -1361,13 +1361,13 @@ public class DefaultListableBeanFactoryTests {
...
@@ -1361,13 +1361,13 @@ public class DefaultListableBeanFactoryTests {
public
void
testImplicitDependsOnCycle
()
{
public
void
testImplicitDependsOnCycle
()
{
DefaultListableBeanFactory
lbf
=
new
DefaultListableBeanFactory
();
DefaultListableBeanFactory
lbf
=
new
DefaultListableBeanFactory
();
RootBeanDefinition
bd1
=
new
RootBeanDefinition
(
TestBean
.
class
);
RootBeanDefinition
bd1
=
new
RootBeanDefinition
(
TestBean
.
class
);
bd1
.
setDependsOn
(
new
String
[]
{
"tb2"
}
);
bd1
.
setDependsOn
(
"tb2"
);
lbf
.
registerBeanDefinition
(
"tb1"
,
bd1
);
lbf
.
registerBeanDefinition
(
"tb1"
,
bd1
);
RootBeanDefinition
bd2
=
new
RootBeanDefinition
(
TestBean
.
class
);
RootBeanDefinition
bd2
=
new
RootBeanDefinition
(
TestBean
.
class
);
bd2
.
setDependsOn
(
new
String
[]
{
"tb3"
}
);
bd2
.
setDependsOn
(
"tb3"
);
lbf
.
registerBeanDefinition
(
"tb2"
,
bd2
);
lbf
.
registerBeanDefinition
(
"tb2"
,
bd2
);
RootBeanDefinition
bd3
=
new
RootBeanDefinition
(
TestBean
.
class
);
RootBeanDefinition
bd3
=
new
RootBeanDefinition
(
TestBean
.
class
);
bd3
.
setDependsOn
(
new
String
[]
{
"tb1"
}
);
bd3
.
setDependsOn
(
"tb1"
);
lbf
.
registerBeanDefinition
(
"tb3"
,
bd3
);
lbf
.
registerBeanDefinition
(
"tb3"
,
bd3
);
try
{
try
{
lbf
.
preInstantiateSingletons
();
lbf
.
preInstantiateSingletons
();
...
@@ -1540,7 +1540,7 @@ public class DefaultListableBeanFactoryTests {
...
@@ -1540,7 +1540,7 @@ public class DefaultListableBeanFactoryTests {
}
}
@Test
@Test
public
void
testGetBeanByTypeInstanceWithPrimary
()
throws
Exception
{
public
void
testGetBeanByTypeInstanceWithPrimary
()
{
DefaultListableBeanFactory
lbf
=
new
DefaultListableBeanFactory
();
DefaultListableBeanFactory
lbf
=
new
DefaultListableBeanFactory
();
RootBeanDefinition
bd1
=
createConstructorDependencyBeanDefinition
(
99
);
RootBeanDefinition
bd1
=
createConstructorDependencyBeanDefinition
(
99
);
RootBeanDefinition
bd2
=
createConstructorDependencyBeanDefinition
(
43
);
RootBeanDefinition
bd2
=
createConstructorDependencyBeanDefinition
(
43
);
...
@@ -1553,7 +1553,7 @@ public class DefaultListableBeanFactoryTests {
...
@@ -1553,7 +1553,7 @@ public class DefaultListableBeanFactoryTests {
}
}
@Test
@Test
public
void
testGetBeanByTypeInstanceWithMultiplePrimary
()
throws
Exception
{
public
void
testGetBeanByTypeInstanceWithMultiplePrimary
()
{
DefaultListableBeanFactory
lbf
=
new
DefaultListableBeanFactory
();
DefaultListableBeanFactory
lbf
=
new
DefaultListableBeanFactory
();
RootBeanDefinition
bd1
=
createConstructorDependencyBeanDefinition
(
99
);
RootBeanDefinition
bd1
=
createConstructorDependencyBeanDefinition
(
99
);
RootBeanDefinition
bd2
=
createConstructorDependencyBeanDefinition
(
43
);
RootBeanDefinition
bd2
=
createConstructorDependencyBeanDefinition
(
43
);
...
@@ -1584,16 +1584,35 @@ public class DefaultListableBeanFactoryTests {
...
@@ -1584,16 +1584,35 @@ public class DefaultListableBeanFactoryTests {
try
{
try
{
lbf
.
getBean
(
TestBean
.
class
,
67
);
lbf
.
getBean
(
TestBean
.
class
,
67
);
fail
(
"Should have thrown NoSuchBeanDefinitionException"
);
fail
(
"Should have thrown NoSuchBeanDefinitionException"
);
}
catch
(
NoSuchBeanDefinitionException
ex
)
{
}
catch
(
NoSuchBeanDefinitionException
ex
)
{
// expected
// expected
}
}
}
}
private
RootBeanDefinition
createConstructorDependencyBeanDefinition
(
int
age
)
{
@Test
public
void
testGetBeanWithArgsNotCreatedForFactoryBeanChecking
()
{
DefaultListableBeanFactory
lbf
=
new
DefaultListableBeanFactory
();
RootBeanDefinition
bd1
=
new
RootBeanDefinition
(
ConstructorDependency
.
class
);
RootBeanDefinition
bd1
=
new
RootBeanDefinition
(
ConstructorDependency
.
class
);
bd1
.
setScope
(
RootBeanDefinition
.
SCOPE_PROTOTYPE
);
bd1
.
setScope
(
RootBeanDefinition
.
SCOPE_PROTOTYPE
);
bd1
.
getConstructorArgumentValues
().
addGenericArgumentValue
(
String
.
valueOf
(
age
));
lbf
.
registerBeanDefinition
(
"bd1"
,
bd1
);
return
bd1
;
RootBeanDefinition
bd2
=
new
RootBeanDefinition
(
ConstructorDependencyFactoryBean
.
class
);
bd2
.
setScope
(
RootBeanDefinition
.
SCOPE_PROTOTYPE
);
lbf
.
registerBeanDefinition
(
"bd2"
,
bd2
);
ConstructorDependency
bean
=
lbf
.
getBean
(
ConstructorDependency
.
class
,
42
);
assertThat
(
bean
.
beanName
,
equalTo
(
"bd1"
));
assertThat
(
bean
.
spouseAge
,
equalTo
(
42
));
assertEquals
(
1
,
lbf
.
getBeanNamesForType
(
ConstructorDependency
.
class
).
length
);
assertEquals
(
1
,
lbf
.
getBeanNamesForType
(
ConstructorDependencyFactoryBean
.
class
).
length
);
}
private
RootBeanDefinition
createConstructorDependencyBeanDefinition
(
int
age
)
{
RootBeanDefinition
bd
=
new
RootBeanDefinition
(
ConstructorDependency
.
class
);
bd
.
setScope
(
RootBeanDefinition
.
SCOPE_PROTOTYPE
);
bd
.
getConstructorArgumentValues
().
addGenericArgumentValue
(
String
.
valueOf
(
age
));
return
bd
;
}
}
@Test
@Test
...
@@ -1664,8 +1683,8 @@ public class DefaultListableBeanFactoryTests {
...
@@ -1664,8 +1683,8 @@ public class DefaultListableBeanFactoryTests {
}
}
catch
(
UnsatisfiedDependencyException
ex
)
{
catch
(
UnsatisfiedDependencyException
ex
)
{
// expected
// expected
assertTrue
(
ex
.
getMessage
().
indexOf
(
"test"
)
!=
-
1
);
assertTrue
(
ex
.
getMessage
().
contains
(
"test"
)
);
assertTrue
(
ex
.
getMessage
().
indexOf
(
"spouse"
)
!=
-
1
);
assertTrue
(
ex
.
getMessage
().
contains
(
"spouse"
)
);
}
}
}
}
...
@@ -1682,8 +1701,8 @@ public class DefaultListableBeanFactoryTests {
...
@@ -1682,8 +1701,8 @@ public class DefaultListableBeanFactoryTests {
}
}
catch
(
UnsatisfiedDependencyException
ex
)
{
catch
(
UnsatisfiedDependencyException
ex
)
{
// expected
// expected
assertTrue
(
ex
.
getMessage
().
indexOf
(
"test"
)
!=
-
1
);
assertTrue
(
ex
.
getMessage
().
contains
(
"test"
)
);
assertTrue
(
ex
.
getMessage
().
indexOf
(
"spouse"
)
!=
-
1
);
assertTrue
(
ex
.
getMessage
().
contains
(
"spouse"
)
);
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录