Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
b41e3956
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,发现更多精彩内容 >>
提交
b41e3956
编写于
11月 19, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revised scope inheritance: default scope is "" (empty String) now; consistent isPrototype checks
上级
ee533080
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
34 addition
and
16 deletion
+34
-16
org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java
.../springframework/beans/factory/config/BeanDefinition.java
+8
-0
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
...s/factory/support/AbstractAutowireCapableBeanFactory.java
+1
-1
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java
...amework/beans/factory/support/AbstractBeanDefinition.java
+21
-10
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
...gframework/beans/factory/support/AbstractBeanFactory.java
+1
-1
org.springframework.beans/src/main/resources/org/springframework/beans/factory/xml/spring-beans-3.0.xsd
...rg/springframework/beans/factory/xml/spring-beans-3.0.xsd
+3
-4
未找到文件。
org.springframework.beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java
浏览文件 @
b41e3956
...
...
@@ -211,9 +211,17 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
/**
* Return whether this a <b>Singleton</b>, with a single, shared instance
* returned on all calls.
* @see #SCOPE_SINGLETON
*/
boolean
isSingleton
();
/**
* Return whether this a <b>Prototype</b>, with an independent instance
* returned for each call.
* @see #SCOPE_PROTOTYPE
*/
boolean
isPrototype
();
/**
* Return whether this bean is "abstract", that is, not meant to be instantiated.
*/
...
...
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
浏览文件 @
b41e3956
...
...
@@ -301,7 +301,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
RootBeanDefinition
bd
=
null
;
if
(
mbd
instanceof
RootBeanDefinition
)
{
RootBeanDefinition
rbd
=
(
RootBeanDefinition
)
mbd
;
if
(
SCOPE_PROTOTYPE
.
equals
(
rbd
.
getScope
()
))
{
if
(
rbd
.
isPrototype
(
))
{
bd
=
rbd
;
}
}
...
...
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java
浏览文件 @
b41e3956
...
...
@@ -33,6 +33,7 @@ import org.springframework.core.io.Resource;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
/**
* Base class for concrete, full-fledged
...
...
@@ -54,6 +55,13 @@ import org.springframework.util.ObjectUtils;
public
abstract
class
AbstractBeanDefinition
extends
BeanMetadataAttributeAccessor
implements
BeanDefinition
,
Cloneable
{
/**
* Constant for the default scope name: "", equivalent to singleton status
* but to be overridden from a parent bean definition (if applicable).
*/
public
static
final
String
SCOPE_DEFAULT
=
""
;
/**
* Constant that indicates no autowiring at all.
* @see #setAutowireMode
...
...
@@ -118,7 +126,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
private
volatile
Object
beanClass
;
private
String
scope
;
private
String
scope
=
SCOPE_DEFAULT
;
private
boolean
singleton
=
true
;
...
...
@@ -273,16 +281,16 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* </ul>
*/
public
void
overrideFrom
(
BeanDefinition
other
)
{
if
(
other
.
getBeanClassName
()
!=
null
)
{
if
(
StringUtils
.
hasLength
(
other
.
getBeanClassName
())
)
{
setBeanClassName
(
other
.
getBeanClassName
());
}
if
(
other
.
getFactoryBeanName
()
!=
null
)
{
if
(
StringUtils
.
hasLength
(
other
.
getFactoryBeanName
())
)
{
setFactoryBeanName
(
other
.
getFactoryBeanName
());
}
if
(
other
.
getFactoryMethodName
()
!=
null
)
{
if
(
StringUtils
.
hasLength
(
other
.
getFactoryMethodName
())
)
{
setFactoryMethodName
(
other
.
getFactoryMethodName
());
}
if
(
other
.
getScope
()
!=
null
)
{
if
(
StringUtils
.
hasLength
(
other
.
getScope
())
)
{
setScope
(
other
.
getScope
());
}
setAbstract
(
other
.
isAbstract
());
...
...
@@ -306,11 +314,11 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
setDependsOn
(
otherAbd
.
getDependsOn
());
setNonPublicAccessAllowed
(
otherAbd
.
isNonPublicAccessAllowed
());
setLenientConstructorResolution
(
otherAbd
.
isLenientConstructorResolution
());
if
(
otherAbd
.
getInitMethodName
()
!=
null
)
{
if
(
StringUtils
.
hasLength
(
otherAbd
.
getInitMethodName
())
)
{
setInitMethodName
(
otherAbd
.
getInitMethodName
());
setEnforceInitMethod
(
otherAbd
.
isEnforceInitMethod
());
}
if
(
otherAbd
.
getDestroyMethodName
()
!=
null
)
{
if
(
StringUtils
.
hasLength
(
otherAbd
.
getDestroyMethodName
())
)
{
setDestroyMethodName
(
otherAbd
.
getDestroyMethodName
());
setEnforceDestroyMethod
(
otherAbd
.
isEnforceDestroyMethod
());
}
...
...
@@ -405,14 +413,17 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Set the name of the target scope for the bean.
* <p>Default is "singleton"; the out-of-the-box alternative is "prototype".
* Extended bean factories might support further scopes.
* <p>Default is singleton status, although this is only applied once
* a bean definition becomes active in the containing factory. A bean
* definition may eventually inherit its scope from a parent bean definitionFor this
* reason, the default scope name is empty (empty String), with
* singleton status being assumed until a resolved scope will be set.
* @see #SCOPE_SINGLETON
* @see #SCOPE_PROTOTYPE
*/
public
void
setScope
(
String
scope
)
{
this
.
scope
=
scope
;
this
.
singleton
=
SCOPE_SINGLETON
.
equals
(
scope
);
this
.
singleton
=
SCOPE_SINGLETON
.
equals
(
scope
)
||
SCOPE_DEFAULT
.
equals
(
scope
)
;
this
.
prototype
=
SCOPE_PROTOTYPE
.
equals
(
scope
);
}
...
...
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
浏览文件 @
b41e3956
...
...
@@ -1115,7 +1115,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
// Set default singleton scope, if not configured before.
if
(
mbd
.
getScope
()
==
null
)
{
if
(
!
StringUtils
.
hasLength
(
mbd
.
getScope
())
)
{
mbd
.
setScope
(
RootBeanDefinition
.
SCOPE_SINGLETON
);
}
...
...
org.springframework.beans/src/main/resources/org/springframework/beans/factory/xml/spring-beans-3.0.xsd
浏览文件 @
b41e3956
...
...
@@ -260,15 +260,14 @@
The scope of this bean: typically "singleton" (one shared instance,
which will be returned by all calls to getBean with the given id), or
"prototype" (independent instance resulting from each call to getBean).
Default is "singleton".
By default, a bean will be a singleton, unless the bean has a parent
bean definition in which case it will inherit the parent's scope.
Singletons are most commonly used, and are ideal for multi-threaded
service objects. Further scopes, such as "request" or "session", might
be supported by extended bean factories (e.g. in a web environment).
Note: This attribute will not be inherited by child bean definitions.
Hence, it needs to be specified per concrete bean definition.
Inner bean definitions inherit the singleton status of their containing
bean definition, unless explicitly specified: The inner bean will be a
singleton if the containing bean is a singleton, and a prototype if
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录