Spring bean的作用域及生命周期(转载)

当new一个classpathxmlapplicationcontext的时候,默认作用域为singleton(作用域为singleton一new的时候就会先执行1、2、3prototype的话,会在getbean()的时候再执行1、2、3,且有几次getbean()就执行几次1、2、3,即每getbean()一次返回一个bean的实例)

前提:无参构造器创建bean

1.先执行无参构造里面的方法

2.执行set方法

3.init()

4.使用get方法

5.destroy()

 

 

<bean id="life_singleton" class="com.bean.LifeBean" scope="singleton" 
            init-method="init" destroy-method="destory" lazy-init="true"/>

 

Spring bean的作用域及生命周期

https://blog.csdn.net/fuzhongmin05/article/details/73389779

https://www.cnblogs.com/Doaoao/p/10741333.html

生命周期:

https://www.jianshu.com/p/ebbb129612ec

https://www.jianshu.com/p/7fe80fe593be

posted @ 2020-03-17 11:54  何浩源  阅读(137)  评论(0编辑  收藏  举报
//一下两个链接最好自己保存下来,再上传到自己的博客园的“文件”选项中