zoukankan      html  css  js  c++  java
  • SpringIOC源码学习总结

    入口方法:AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(MyConfig.class);
    初始化容器后,关注refresh()方法,该方法是synchronized修饰,所以之后都是安全的。 之后关注registerBeanPostProcessors();finishBeanFactoryInitialization(beanFactory);,前者实例化beanPostProcessors,后者实例化非lazy的singletonBan.

    finishBeanFactoryInitialization(beanFactory)

    重点关注beanFactory.getBean();
    ->createBean();->doCreateBean的时候会依次执行createBeanInstance();populateBean();initializeBean,分别是创建实例注入属性执行初始化方法

    initializeBean()会先响应目标bean实现的aware接口->invokeAwareMethods.
    接着applyBeanPostProcessorsBeforeInitialization以及invokeInitMethods(该方法包含initializeBean的afterPropertiesSet调用以及bean指定的initMethod方法)
    然后applyBeanPostProcessorsAfterInitialization(包含得到代理对象等)
    之后再设置disposable方法。
    最后通过addSingleton(beanName, singletonObject);将其加入缓存。

    看图比较直接:
    在这里插入图片描述
    ps: Spring 在实现其bean生命周期的同时,还实现了JSR_250定义的@PostConstruct、@PreDestory、@Resource, 其中 @PostConstruct执行实际是在afterPropertiesSet与initMehotd之前。@PreDestory 在 DisposableBean的destroy之前。

  • 相关阅读:
    Roadblocks(poj 3255)
    最小集合(51nod 1616)
    绿色通道(codevs 3342)
    解的个数(codevs 1213)
    多米诺(codevs 3052)
    abcd
    dwarf tower
    第K 小数
    noip2016复习
    文化之旅(洛谷 1078)
  • 原文地址:https://www.cnblogs.com/thewindkee/p/12873162.html
Copyright © 2011-2022 走看看