zoukankan      html  css  js  c++  java
  • 好记性不如烂笔头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">

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

  • 相关阅读:
    牛客练习赛83题解
    1525 F. Goblins And Gnomes (最小顶点覆盖输出方案)
    hash表
    欧拉回路输出方案
    dp优化
    1
    fwt原理学习和一些拓展
    SpringBoot在IDEA中的配置
    ES: memory locking requested for elasticsearch process but memory is not locked
    Prometheus监控大数据
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4720728.html
Copyright © 2011-2022 走看看