好记性不如烂笔头85-spring3学习(6)-BeanFactory 于bean生命周期

假设BeanFactory为了产生、管理Bean, 一个Bean从成立到毁灭。它会经过几个阶段运行。


据我所知,一般bean包括在生命周期:设定,初始化,使用阶段,四个核心阶段销毁。

1、@Bean的建立
由BeanFactory读取Bean定义文件,并生成各个Bean实例。

2、初始化@属性注入
运行相关的Bean属性依赖注入

@BeanNameAware的setBeanName()
org.springframework.beans.factory.BeanNameAware

@BeanFactoryAware的setBeanFactory()
org.springFramework.beans.factory.BeanFactoryAware

@BeanPostProcessors的processBeforeInitialization()
org.springFramework.beans.factory.config.BeanPostProcessors

@InitializiongBean的afterPropertiesSet()
org.springframework.beans.factory.InitializingBean

@Bean定义文件里定义init-method
use “init-methd” to set method name e.g:

<bean id="helloBean" class="org.bearfly.bean.HelloBean" init-method="initBean">

当代码运行到这个阶段的时候。就是运行initBean方法。

@BeanPostProcessors的processaAfterInitialization()
假设有不论什么的BeanPostProcessors实例与Bean实例关联。则运行BeanPostProcessor实例的processaAfterInitialization()方法。

4、销毁 @DisposableBean的destroy()
容器关闭 org.springframework.beans.factory.DisposableBean

@Bean定义文件里定义destroy-method

<bean id="helloBean" class="org.bearfly.bean.HelloBean" destroy-method="destroyBean">

版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值