Spring bean的作用域

7.5 Bean scopes
When you create a bean definition, you create a recipe for creating actual instances of the class defined by that bean definition. The idea that a bean definition is a recipe is important, because it means that,as with a class, you can create many object instances from a single recipe.
You can control not only the various dependencies and configuration values that are to be plugged into
an object that is created from a particular bean definition, but also the scope of the objects created from a particular bean definition. This approach is powerful and flexible in that you can choose the scope of the objects you create through configuration instead of having to bake in the scope of an object at the Java class level. Beans can be defined to be deployed in one of a number of scopes: out of the
box, the Spring Framework supports seven scopes, five of which are available only if you use a webaware ApplicationContext.
The following scopes are supported out of the box. You can also create a custom scope.

Spring bean的作用域

Bean的作用域分7种:
singleton:单例(在每一个Spring容器中只实例化一个对象)
prototype:一个bean可以生成任意数量的对象实例
request:在每一次Http请求后都会产生一个bean实例
session:在每一个session中实例化一次
globalSession:在全局session中实例化
application:在一个应用程序内实例化
websocket:在websocket里实例化