首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Spring中的bean的功用范围

2012-08-22 
Spring中的bean的作用范围当在spring中声明bean的时候,有时需要bean的范围的选项,为了每次都能产生一个新

Spring中的bean的作用范围

当在spring中声明bean的时候,有时需要bean的范围的选项,为了每次都能产生一个新的bean的实例的时候,我们可以在声明bean的时候指定scope属性为prototype

    <bean id="constractor" scope="prototype">  <constructor-arg value="我是通过构造方法注入的"></constructor-arg>  </bean>

?作用范围列表Spring中的bean的功用范围

singleton ----单例(默认) 在spring容器中只有一个实例

prototype----允许bean可以被多次实例化(使用一次创建一个实例)

request------定义bean的作用范围为HTTP请求,只有在web应用中的spring上下文中才有效

session------同request

global-session-----定义bean的范围为全局的HTTP会话

热点排行