版权声明:本文为博主ExcelMann的原创文章,未经博主允许不得转载。
6、Bean的作用域
作者:ExcelMann,转载需注明。
6.1、单例模式(spring默认机制)
<bean id="accountService" class="com.something.DefaultAccountService"/>
<!-- the following is equivalent, though redundant (singleton scope is the default) -->
<bean id="accountService" class="com.something.DefaultAccountService" scope="singleton"/>
6.2、原型模式
原型模式:每次调用getBean,获取的都是一个新的bean。
<bean id="accountService" class="com.something.DefaultAccountService" scope="prototype"/>
8.3、其余模式
其余的request、session、application等模式,都是只能在web应用下使用的,作用域类似于web。