SpringIOC源码解读

推荐:体系化学习Java(Java面试专题)

以下是阅读IOC的源码所看的图,
1、大家要看源码可以通过SpringBoot的main方法,点击run方法,找到 public ConfigurableApplicationContext run(String… args)
2、这个方法里有个 this.refreshContext(context);
3、点击 refreshContext 进去找到 this.refresh(context);
4、点击 refresh 进去找到 ((AbstractApplicationContext)applicationContext).refresh();
5、点击 refresh() 找到 public void refresh() throws BeansException, IllegalStateException

这个就是bean的创建流程,包含了IOC创建bean的全过程。
核心方法如下,结合图学习(图非常大,需要大家耐心点击放大查看,但是内容是干货)。

 this.postProcessBeanFactory(beanFactory);
 this.invokeBeanFactoryPostProcessors(beanFactory);
 this.registerBeanPostProcessors(beanFactory);
 this.initMessageSource();
 this.initApplicationEventMulticaster();
 this.onRefresh();
 this.registerListeners();
 this.finishBeanFactoryInitialization(beanFactory);
 this.finishRefresh();

你可能感兴趣的:(spring,java,jvm,spring)