spring scope

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". 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 the containing bean has 
any other scope.

singleton:单例。默认对象创建时机为容器加载时机
prototype:多例。默认对象创建时机为我们调用该对象时创建。
request和session都是在web环境下使用。
配置文件:


注解方式使用多例:@scope("prototype"),标注在类上,在装载的该类的时候,每次都会新初始化一个该类的实例。

你可能感兴趣的:(spring scope)