zoukankan      html  css  js  c++  java
  • 【spring源码学习】spring的IOC容器在初始化bean过程

    【一】初始化IOC的bean的时候Spring会执行的一些回调方法

    (1)spring bean创建的前置处理

        =>ApplicationContextAwareProcessor 在创建bean的时候调用

          bean.setEnvironment(this.applicationContext.getEnvironment())

          bean.setEmbeddedValueResolver(new EmbeddedValueResolver(this.applicationContext.getBeanFactory()))

          bean.setResourceLoader(this.applicationContext)

          bean.setApplicationEventPublisher(this.applicationContext)

          bean.setMessageSource(this.applicationContext)

          setApplicationContext(this.applicationContext)

        =>在该阶段spring配置的或者我们自定义的 BeanPostProcessor的接口实现会执行postProcessBeforeInitialization(final Object bean, String beanName)方法 中调用相关Aware的接口方法。


    (2)spring的Aware的相关接口的调用

        =>BeanNameAware的setBeanName(beanName)

        =>BeanClassLoaderAware的setBeanClassLoader(getBeanClassLoader())

        =>BeanFactoryAware 的setBeanFactory(AbstractAutowireCapableBeanFactory.this)
    (3)spring的InitializingBean的接口的调用
        =>afterPropertiesSet()方法的调用

    (4)bean中配置的init方法

        =>自定义配置

    (5)spring bean创建的后置处理

        =>在该阶段spring配置的或我们自定义的BeanPostProcessor的接口实现会执行postProcessAfterInitialization(Object bean, String beanName)方法
        =>例如事务管理代理,动态代理的代理对象创建,都在这个环节完成。

  • 相关阅读:
    《杜教筛》
    《洛谷P4213 【模板】杜教筛(Sum)》
    《洛谷P1829 [国家集训队]Crash的数字表格 / JZPTAB》
    《纸牌问题》
    《洛谷P2522 [HAOI2011]Problem b》
    使用urlretrieve下载图片
    scrapy初探
    爬豆瓣电影名
    直接插入排序
    Windows python 3 安装OpenCV
  • 原文地址:https://www.cnblogs.com/shangxiaofei/p/7229930.html
Copyright © 2011-2022 走看看