其他分享
首页 > 其他分享> > spring bean 生命周期

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的

标签:生命周期,spring,called,bean,实例,prototype,lifecycle
来源: https://www.cnblogs.com/huang-jianfeng/p/14766462.html