Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
65743936
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,发现更多精彩内容 >>
提交
65743936
编写于
10月 11, 2012
作者:
J
Juergen Hoeller
提交者:
unknown
10月 12, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Provider injection into prototype beans works for method parameters as well
Issue: SPR-9630
上级
3f1fb4ee
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
84 addition
and
16 deletion
+84
-16
spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java
...gframework/beans/factory/config/DependencyDescriptor.java
+1
-1
spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java
...ry/annotation/InjectAnnotationBeanPostProcessorTests.java
+83
-15
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java
浏览文件 @
65743936
...
...
@@ -126,7 +126,7 @@ public class DependencyDescriptor implements Serializable {
* @param original the original descriptor to create a copy from
*/
public
DependencyDescriptor
(
DependencyDescriptor
original
)
{
this
.
methodParameter
=
original
.
methodParameter
;
this
.
methodParameter
=
(
original
.
methodParameter
!=
null
?
new
MethodParameter
(
original
.
methodParameter
)
:
null
)
;
this
.
field
=
original
.
field
;
this
.
declaringClass
=
original
.
declaringClass
;
this
.
methodName
=
original
.
methodName
;
...
...
spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java
浏览文件 @
65743936
...
...
@@ -372,66 +372,103 @@ public class InjectAnnotationBeanPostProcessorTests {
AutowiredAnnotationBeanPostProcessor
bpp
=
new
AutowiredAnnotationBeanPostProcessor
();
bpp
.
setBeanFactory
(
bf
);
bf
.
addBeanPostProcessor
(
bpp
);
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactoryQualifierInjectionBean
.
class
));
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactoryQualifier
Field
InjectionBean
.
class
));
RootBeanDefinition
bd
=
new
RootBeanDefinition
(
TestBean
.
class
);
bd
.
addQualifier
(
new
AutowireCandidateQualifier
(
Qualifier
.
class
,
"testBean"
));
bf
.
registerBeanDefinition
(
"testBean"
,
bd
);
bf
.
registerBeanDefinition
(
"testBean2"
,
new
RootBeanDefinition
(
TestBean
.
class
));
ObjectFactoryQualifier
InjectionBean
bean
=
(
ObjectFactoryQualifier
InjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
ObjectFactoryQualifier
FieldInjectionBean
bean
=
(
ObjectFactoryQualifierField
InjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
bf
.
destroySingletons
();
}
@Test
public
void
testObjectFactoryInjectionIntoPrototypeBean
()
{
public
void
testObjectFactoryQualifierInjection
()
{
DefaultListableBeanFactory
bf
=
new
DefaultListableBeanFactory
();
AutowiredAnnotationBeanPostProcessor
bpp
=
new
AutowiredAnnotationBeanPostProcessor
();
bpp
.
setBeanFactory
(
bf
);
bf
.
addBeanPostProcessor
(
bpp
);
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactoryQualifierFieldInjectionBean
.
class
));
RootBeanDefinition
bd
=
new
RootBeanDefinition
(
TestBean
.
class
);
bd
.
addQualifier
(
new
AutowireCandidateQualifier
(
Qualifier
.
class
,
"testBean"
));
bf
.
registerBeanDefinition
(
"testBean"
,
bd
);
ObjectFactoryQualifierFieldInjectionBean
bean
=
(
ObjectFactoryQualifierFieldInjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
bf
.
destroySingletons
();
}
@Test
public
void
testObjectFactoryFieldInjectionIntoPrototypeBean
()
{
DefaultListableBeanFactory
bf
=
new
DefaultListableBeanFactory
();
bf
.
setAutowireCandidateResolver
(
new
QualifierAnnotationAutowireCandidateResolver
());
AutowiredAnnotationBeanPostProcessor
bpp
=
new
AutowiredAnnotationBeanPostProcessor
();
bpp
.
setBeanFactory
(
bf
);
bf
.
addBeanPostProcessor
(
bpp
);
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactoryQualifierInjectionBean
.
class
,
false
));
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactoryQualifier
Field
InjectionBean
.
class
,
false
));
RootBeanDefinition
bd
=
new
RootBeanDefinition
(
TestBean
.
class
);
bd
.
addQualifier
(
new
AutowireCandidateQualifier
(
Qualifier
.
class
,
"testBean"
));
bf
.
registerBeanDefinition
(
"testBean"
,
bd
);
bf
.
registerBeanDefinition
(
"testBean2"
,
new
RootBeanDefinition
(
TestBean
.
class
));
ObjectFactoryQualifier
InjectionBean
bean
=
(
ObjectFactoryQualifier
InjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
ObjectFactoryQualifier
FieldInjectionBean
bean
=
(
ObjectFactoryQualifierField
InjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
ObjectFactoryQualifier
InjectionBean
anotherBean
=
(
ObjectFactoryQualifier
InjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
ObjectFactoryQualifier
FieldInjectionBean
anotherBean
=
(
ObjectFactoryQualifierField
InjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
assertNotSame
(
anotherBean
,
bean
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
}
@Test
public
void
testObjectFactory
QualifierInjectio
n
()
{
public
void
testObjectFactory
MethodInjectionIntoPrototypeBea
n
()
{
DefaultListableBeanFactory
bf
=
new
DefaultListableBeanFactory
();
bf
.
setAutowireCandidateResolver
(
new
QualifierAnnotationAutowireCandidateResolver
());
AutowiredAnnotationBeanPostProcessor
bpp
=
new
AutowiredAnnotationBeanPostProcessor
();
bpp
.
setBeanFactory
(
bf
);
bf
.
addBeanPostProcessor
(
bpp
);
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactoryQualifier
InjectionBean
.
class
));
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactoryQualifier
MethodInjectionBean
.
class
,
false
));
RootBeanDefinition
bd
=
new
RootBeanDefinition
(
TestBean
.
class
);
bd
.
addQualifier
(
new
AutowireCandidateQualifier
(
Qualifier
.
class
,
"testBean"
));
bf
.
registerBeanDefinition
(
"testBean"
,
bd
);
bf
.
registerBeanDefinition
(
"testBean2"
,
new
RootBeanDefinition
(
TestBean
.
class
));
ObjectFactoryQualifierMethodInjectionBean
bean
=
(
ObjectFactoryQualifierMethodInjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
ObjectFactoryQualifierMethodInjectionBean
anotherBean
=
(
ObjectFactoryQualifierMethodInjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
assertNotSame
(
anotherBean
,
bean
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
}
@Test
public
void
testObjectFactoryWithBeanField
()
throws
Exception
{
DefaultListableBeanFactory
bf
=
new
DefaultListableBeanFactory
();
AutowiredAnnotationBeanPostProcessor
bpp
=
new
AutowiredAnnotationBeanPostProcessor
();
bpp
.
setBeanFactory
(
bf
);
bf
.
addBeanPostProcessor
(
bpp
);
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactoryFieldInjectionBean
.
class
));
bf
.
registerBeanDefinition
(
"testBean"
,
new
RootBeanDefinition
(
TestBean
.
class
));
bf
.
setSerializationId
(
"test"
);
ObjectFactoryQualifierInjectionBean
bean
=
(
ObjectFactoryQualifierInjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
ObjectFactoryFieldInjectionBean
bean
=
(
ObjectFactoryFieldInjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
bean
=
(
ObjectFactoryFieldInjectionBean
)
SerializationTestUtils
.
serializeAndDeserialize
(
bean
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
bf
.
destroySingletons
();
}
@Test
public
void
testObjectFactory
Serialization
()
throws
Exception
{
public
void
testObjectFactory
WithBeanMethod
()
throws
Exception
{
DefaultListableBeanFactory
bf
=
new
DefaultListableBeanFactory
();
AutowiredAnnotationBeanPostProcessor
bpp
=
new
AutowiredAnnotationBeanPostProcessor
();
bpp
.
setBeanFactory
(
bf
);
bf
.
addBeanPostProcessor
(
bpp
);
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactoryInjectionBean
.
class
));
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ObjectFactory
Method
InjectionBean
.
class
));
bf
.
registerBeanDefinition
(
"testBean"
,
new
RootBeanDefinition
(
TestBean
.
class
));
bf
.
setSerializationId
(
"test"
);
ObjectFactory
InjectionBean
bean
=
(
ObjectFactory
InjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
ObjectFactory
MethodInjectionBean
bean
=
(
ObjectFactoryMethod
InjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
bean
=
(
ObjectFactoryInjectionBean
)
SerializationTestUtils
.
serializeAndDeserialize
(
bean
);
bean
=
(
ObjectFactory
Method
InjectionBean
)
SerializationTestUtils
.
serializeAndDeserialize
(
bean
);
assertSame
(
bf
.
getBean
(
"testBean"
),
bean
.
getTestBean
());
bf
.
destroySingletons
();
}
...
...
@@ -901,7 +938,7 @@ public class InjectAnnotationBeanPostProcessorTests {
}
public
static
class
ObjectFactoryInjectionBean
implements
Serializable
{
public
static
class
ObjectFactory
Field
InjectionBean
implements
Serializable
{
@Inject
private
Provider
<
TestBean
>
testBeanFactory
;
...
...
@@ -912,7 +949,22 @@ public class InjectAnnotationBeanPostProcessorTests {
}
public
static
class
ObjectFactoryQualifierInjectionBean
{
public
static
class
ObjectFactoryMethodInjectionBean
implements
Serializable
{
private
Provider
<
TestBean
>
testBeanFactory
;
@Inject
public
void
setTestBeanFactory
(
Provider
<
TestBean
>
testBeanFactory
)
{
this
.
testBeanFactory
=
testBeanFactory
;
}
public
TestBean
getTestBean
()
{
return
this
.
testBeanFactory
.
get
();
}
}
public
static
class
ObjectFactoryQualifierFieldInjectionBean
{
@Inject
@Named
(
"testBean"
)
...
...
@@ -924,6 +976,22 @@ public class InjectAnnotationBeanPostProcessorTests {
}
public
static
class
ObjectFactoryQualifierMethodInjectionBean
{
private
Provider
<?>
testBeanFactory
;
@Inject
@Named
(
"testBean"
)
public
void
setTestBeanFactory
(
Provider
<?>
testBeanFactory
)
{
this
.
testBeanFactory
=
testBeanFactory
;
}
public
TestBean
getTestBean
()
{
return
(
TestBean
)
this
.
testBeanFactory
.
get
();
}
}
public
static
class
ObjectFactoryListFieldInjectionBean
implements
Serializable
{
@Inject
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录