Bean 作用域

来源:互联网 发布:visio for mac dmg 编辑:程序博客网 时间:2024/06/05 18:30

singleton: 默认
prototype:

<bean id = "car" class = "com.smart.Car" scope = "singleton">getBean("car"); 每次都是获取同一个car实例。 prototype :每次获得一个新的scope

与web应用环境相关的Bean作用域。
request:
session:
globalSession:

<bean name = "car" class = "com.smart.Car" scope = "request">httP请求,创建一个Bean,请求结束就销毁这个Bean.session: httpSession,session中所有的HTTP请求。globalSession:Portlet的web应用中使用。