目录
BeanScopes
Scope | Description |
---|---|
(Default) Scopes a single bean definition to a single object instance for each Spring IoC container. | |
Scopes a single bean definition to any number of object instances. | |
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 | |
Scopes a single bean definition to the lifecycle of an HTTP | |
Scopes a single bean definition to the lifecycle of a | |
Scopes a single bean definition to the lifecycle of a |
单例模式(Spring默认机制)
Java中单例模式定义:“一个类有且仅有一个实例,并且自行实例化向整个系统提供。”
<bean id="user" class="com.lys.pojo.User" p:name="lys" p:age="18"
scope="singleton"/>
原型模式
每次从容器中get的时候,都会产生一个新的对象
<bean id="user" class="com.lys.pojo.User" p:name="lys" p:age="18"
scope="prototype"/>
其余的request、session、application、这些只能在web开发中使用到