Bean的作用域

来源:互联网 发布:血色衣冠4.0武将数据 编辑:程序博客网 时间:2024/05/17 03:07

1、singleton

每个Spring容器中的一个Bean定义只有一个对象实例,默认情况会在容器启动的时候初始化Bean,可以指定Bean节点的lazy-init="true"来延缓初始化Bean,

这个时候只有第一次获取bean才会初始化。

<bean id="xxx" class="xxx.xxx" lazy-init="true">

2、prototype

每次从容器获取bean都是新的对象

<bean id="xxx" class="xxx.xxx" scope="prototype">

3、web

request

session

golobal session