spring bean 生命周期

1 singleton

spring 默认的模式,下面两种方式等价

<bean id="accountService" class="com.something.DefaultAccountService"/>

 <bean id="accountService" class="com.something.DefaultAccountService" scope="singleton"/>

每个spring容器只有一个实例

2prototype

每一个请求就容器就会创造一个实例

注意: Thus, although initialization lifecycle callback methods are called on all objects regardless of scope, in the case of prototypes, configured destruction lifecycle callbacks are not called.

bean的初始化方法会被调用,但是销毁时的disposal方法不会被调用,

  

. Singleton Beans with Prototype-bean Dependencies

即使一个prototype的bean被注入到单例的bean中他依然是prototype的

上一篇:Python3通过函数名调用函数的几种场景实现


下一篇:虚(virtual)析构函数