Spring4 bean的作用域包含以下几种,同时你也可以创建自己定义的作用域。

官网解释:

singleton

(Default) Scopes a single bean definition to a single object instance per Spring IoC container.
译:(默认方式)在Spring IoC容器中都只有单个对象实例。

prototype

Scopes a single bean definition to any number of object instances.
译:将单个bean定义范围限定为任意数量的对象实例。

request

Scopes a single bean definition to the lifecycle of a single HTTP request; that is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.
译:将单个bean定义的范围限定为单个HTTP请求的生命周期; 也就是说,每个HTTP请求都有自己的bean实例,它是从单个bean定义的后面创建的。 仅在Web感知Spring ApplicationContext 的上下文中有效。

session

Scopes a single bean definition to the lifecycle of an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.
译:将单个bean定义范围限定为HTTP Session 的生命周期。 仅在Web感知Spring ApplicationContext 的上下文中有效。

globalSession

Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a Portlet context. Only valid in the context of a web-aware Spring ApplicationContext.
译:将单个bean定义的范围限定为全局HTTP会话的生命周期。 通常仅在在Portlet上下文中使用时有效。 只在Web感知Spring ApplicationContext的上下文中有效。

application

Scopes a single bean definition to the lifecycle of a ServletContext. Only valid in the context of a web-aware Spring ApplicationContext.
译:将单个bean定义范围限定为ServletContext的生命周期。 只在Web感知Spring ApplicationContext的上下文中有效。

websocket

Scopes a single bean definition to the lifecycle of a WebSocket. Only valid in the context of a web-aware Spring ApplicationContext.
译: 将单个bean定义范围限定为WebSocket的生命周期。 只在Web感知Spring ApplicationContext的上下文中有效。