bean的作用域
Bean Scope
| Scope | 说明 |
|---|---|
| singleton | (默认情况下)为每个Spring IoC容器将单个Bean定义的Scope扩大到单个对象实例。 |
| prototype | 将单个Bean定义的Scope扩大到任何数量的对象实例。 |
| session | 将单个Bean定义的Scope扩大到一个HTTP Session 的生命周期。只在Web感知的Spring ApplicationContext 的上下文中有效。 |
| application | 将单个Bean定义的 Scope 扩大到 ServletContext 的生命周期中。只在Web感知的Spring ApplicationContext 的上下文中有效。 |
| websocket | 将单个Bean定义的 Scope 扩大到 WebSocket 的生命周期。仅在具有Web感知的 Spring ApplicationContext 的上下文中有效。 |
1. The Singleton Scope 单例模式 (Spring默认机制)
单例模式
Only one instance is ever created…[创建的所有实例只有一个]无论用几个dao来拿最终都为一个

<bean class="org.example.pojo.Hello" id="hello" scope="singleton"/>
2. Prototype Scope 原型模式
每次从容器get的时候, 会产生一个新对象

<bean class="org.example.pojo.Hello" id="hello" scope="prototype"/>
占资源
- 其余的 request, session, application,这些个在web开发者使用~



















