官方文档:
翻译过来就是:
一、单例模式(默认)
当您定义一个bean定义并将其定义为一个单例对象时,Spring IoC容器将仅创建该bean定义定义的对象的一个实例。此单一实例存储在此类单例bean的缓存中,该指定bean的所有后续请求和引用都将返回缓存的对象。
也就是说:每次getBean拿到的都是同一个对象。
<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"/>
二、原型模式
每次发出对特定bean的请求时都会创建一个新的bean实例。
也就是说,每次getBean返回的对象都不一样。
scope="prototype"
<bean id="accountService" class="com.something.DefaultAccountService" scope="prototype"/>