Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
c986a1ef
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,发现更多精彩内容 >>
提交
c986a1ef
编写于
3月 01, 2013
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cache target type per bean definition and allow for specifying it in advance
Issue: SPR-10335
上级
6a043e3e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
15 deletion
+39
-15
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
...s/factory/support/AbstractAutowireCapableBeanFactory.java
+14
-9
spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
...ngframework/beans/factory/support/RootBeanDefinition.java
+25
-6
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
浏览文件 @
c986a1ef
...
@@ -572,17 +572,22 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
...
@@ -572,17 +572,22 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
}
@Override
@Override
protected
Class
predictBeanType
(
String
beanName
,
RootBeanDefinition
mbd
,
Class
...
typesToMatch
)
{
protected
Class
<?>
predictBeanType
(
String
beanName
,
RootBeanDefinition
mbd
,
Class
...
typesToMatch
)
{
Class
beanClass
=
(
mbd
.
getFactoryMethodName
()
!=
null
?
Class
<?>
targetType
=
mbd
.
getTargetType
();
getTypeForFactoryMethod
(
beanName
,
mbd
,
typesToMatch
)
:
if
(
targetType
==
null
)
{
resolveBeanClass
(
mbd
,
beanName
,
typesToMatch
));
targetType
=
(
mbd
.
getFactoryMethodName
()
!=
null
?
getTypeForFactoryMethod
(
beanName
,
mbd
,
typesToMatch
)
:
resolveBeanClass
(
mbd
,
beanName
,
typesToMatch
));
if
(
ObjectUtils
.
isEmpty
(
typesToMatch
)
||
getTempClassLoader
()
==
null
)
{
mbd
.
setTargetType
(
targetType
);
}
}
// Apply SmartInstantiationAwareBeanPostProcessors to predict the
// Apply SmartInstantiationAwareBeanPostProcessors to predict the
// eventual type after a before-instantiation shortcut.
// eventual type after a before-instantiation shortcut.
if
(
beanClass
!=
null
&&
!
mbd
.
isSynthetic
()
&&
hasInstantiationAwareBeanPostProcessors
())
{
if
(
targetType
!=
null
&&
!
mbd
.
isSynthetic
()
&&
hasInstantiationAwareBeanPostProcessors
())
{
for
(
BeanPostProcessor
bp
:
getBeanPostProcessors
())
{
for
(
BeanPostProcessor
bp
:
getBeanPostProcessors
())
{
if
(
bp
instanceof
SmartInstantiationAwareBeanPostProcessor
)
{
if
(
bp
instanceof
SmartInstantiationAwareBeanPostProcessor
)
{
SmartInstantiationAwareBeanPostProcessor
ibp
=
(
SmartInstantiationAwareBeanPostProcessor
)
bp
;
SmartInstantiationAwareBeanPostProcessor
ibp
=
(
SmartInstantiationAwareBeanPostProcessor
)
bp
;
Class
predicted
=
ibp
.
predictBeanType
(
beanClass
,
beanName
);
Class
predicted
=
ibp
.
predictBeanType
(
targetType
,
beanName
);
if
(
predicted
!=
null
&&
(
typesToMatch
.
length
!=
1
||
!
FactoryBean
.
class
.
equals
(
typesToMatch
[
0
])
||
if
(
predicted
!=
null
&&
(
typesToMatch
.
length
!=
1
||
!
FactoryBean
.
class
.
equals
(
typesToMatch
[
0
])
||
FactoryBean
.
class
.
isAssignableFrom
(
predicted
)))
{
FactoryBean
.
class
.
isAssignableFrom
(
predicted
)))
{
return
predicted
;
return
predicted
;
...
@@ -590,7 +595,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
...
@@ -590,7 +595,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
}
}
}
}
}
return
beanClass
;
return
targetType
;
}
}
/**
/**
...
@@ -607,8 +612,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
...
@@ -607,8 +612,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @return the type for the bean if determinable, or {@code null} else
* @return the type for the bean if determinable, or {@code null} else
* @see #createBean
* @see #createBean
*/
*/
protected
Class
getTypeForFactoryMethod
(
String
beanName
,
RootBeanDefinition
mbd
,
Class
[]
typesToMatch
)
{
protected
Class
<?>
getTypeForFactoryMethod
(
String
beanName
,
RootBeanDefinition
mbd
,
Class
[]
typesToMatch
)
{
Class
factoryClass
;
Class
<?>
factoryClass
;
boolean
isStatic
=
true
;
boolean
isStatic
=
true
;
String
factoryBeanName
=
mbd
.
getFactoryBeanName
();
String
factoryBeanName
=
mbd
.
getFactoryBeanName
();
...
...
spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
浏览文件 @
c986a1ef
/*
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
3
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.
...
@@ -61,8 +61,12 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
...
@@ -61,8 +61,12 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
boolean
allowCaching
=
true
;
boolean
allowCaching
=
true
;
private
volatile
Class
<?>
targetType
;
boolean
isFactoryMethodUnique
=
false
;
boolean
isFactoryMethodUnique
=
false
;
final
Object
constructorArgumentLock
=
new
Object
();
/** Package-visible field for caching the resolved constructor or factory method */
/** Package-visible field for caching the resolved constructor or factory method */
Object
resolvedConstructorOrFactoryMethod
;
Object
resolvedConstructorOrFactoryMethod
;
...
@@ -75,15 +79,13 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
...
@@ -75,15 +79,13 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
/** Package-visible field for caching partly prepared constructor arguments */
/** Package-visible field for caching partly prepared constructor arguments */
Object
[]
preparedConstructorArguments
;
Object
[]
preparedConstructorArguments
;
final
Object
constructorArgumentLock
=
new
Object
();
final
Object
postProcessingLock
=
new
Object
();
/** Package-visible field that indicates a before-instantiation post-processor having kicked in */
volatile
Boolean
beforeInstantiationResolved
;
/** Package-visible field that indicates MergedBeanDefinitionPostProcessor having been applied */
/** Package-visible field that indicates MergedBeanDefinitionPostProcessor having been applied */
boolean
postProcessed
=
false
;
boolean
postProcessed
=
false
;
final
Object
postProcessingLock
=
new
Object
();
/** Package-visible field that indicates a before-instantiation post-processor having kicked in */
volatile
Boolean
beforeInstantiationResolved
;
/**
/**
...
@@ -236,6 +238,8 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
...
@@ -236,6 +238,8 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
if
(
original
instanceof
RootBeanDefinition
)
{
if
(
original
instanceof
RootBeanDefinition
)
{
RootBeanDefinition
originalRbd
=
(
RootBeanDefinition
)
original
;
RootBeanDefinition
originalRbd
=
(
RootBeanDefinition
)
original
;
this
.
decoratedDefinition
=
originalRbd
.
decoratedDefinition
;
this
.
decoratedDefinition
=
originalRbd
.
decoratedDefinition
;
this
.
allowCaching
=
originalRbd
.
allowCaching
;
this
.
targetType
=
originalRbd
.
targetType
;
this
.
isFactoryMethodUnique
=
originalRbd
.
isFactoryMethodUnique
;
this
.
isFactoryMethodUnique
=
originalRbd
.
isFactoryMethodUnique
;
}
}
}
}
...
@@ -251,6 +255,21 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
...
@@ -251,6 +255,21 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
}
}
}
}
/**
* Specify the target type of this bean definition, if known in advance.
*/
public
void
setTargetType
(
Class
<?>
targetType
)
{
this
.
targetType
=
targetType
;
}
/**
* Return the target type of this bean definition, if known
* (either specified in advance or resolved on first instantiation).
*/
public
Class
<?>
getTargetType
()
{
return
this
.
targetType
;
}
/**
/**
* Specify a factory method name that refers to a non-overloaded method.
* Specify a factory method name that refers to a non-overloaded method.
*/
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录