Spring中bean的scope

旧版本了,在xml中定义才有的。其实现在基于注解都没怎么折腾这个的了。

Scope说明
singleton默认)每个 Spring IoC 容器将单个 Bean 定义的 Scope 指定为单个对象实例。
prototype将单个 Bean 定义的 Scope 扩大到任意数量的对象实例。
request将单个 Bean 定义的 Scope 扩大到单个 HTTP 请求的生命周期。也就是说,每个 HTTP 请求都有自己的 Bean 实例,该实例是在单个 Bean 定义的基础上创建的。只在 Web 感知的 Spring ApplicationContext 的上下文中有效。
session将单个 Bean 定义的 Scope 扩大到一个 HTTP 会话的生命周期。只在 Web 感知的 Spring ApplicationContext 的上下文中有效。
application将单个 Bean 定义的 Scope 扩大到 ServletContext 的生命周期中。只在 Web 感知的 Spring ApplicationContext 的上下文中有效。
websocket将单个 Bean 定义的 Scope 扩大到 WebSocket 的生命周期。只在 Web 感知的 Spring ApplicationContext 的上下文中有效。

Comments

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注