博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring源码:Spring IoC容器加载过程(1)
阅读量:4599 次
发布时间:2019-06-09

本文共 2739 字,大约阅读时间需要 9 分钟。

Spring源码版本:4.3.23.RELEASE

一、加载过程概览

Spring容器加载过程可以在org.springframework.context.support.AbstractApplicationContext#refresh方法看到总体过程,具体细节需要断点调试:

1     @Override 2     public void refresh() throws BeansException, IllegalStateException { 3         synchronized (this.startupShutdownMonitor) { 4             // Prepare this context for refreshing. 5             prepareRefresh(); 6  7             // Tell the subclass to refresh the internal bean factory. 8             ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); 9 10             // Prepare the bean factory for use in this context.11             prepareBeanFactory(beanFactory);12 13             try {14                 // Allows post-processing of the bean factory in context subclasses.15                 postProcessBeanFactory(beanFactory);16 17                 // Invoke factory processors registered as beans in the context.18                 invokeBeanFactoryPostProcessors(beanFactory);19 20                 // Register bean processors that intercept bean creation.21                 registerBeanPostProcessors(beanFactory);22 23                 // Initialize message source for this context.24                 initMessageSource();25 26                 // Initialize event multicaster for this context.27                 initApplicationEventMulticaster();28 29                 // Initialize other special beans in specific context subclasses.30                 onRefresh();31 32                 // Check for listener beans and register them.33                 registerListeners();34 35                 // Instantiate all remaining (non-lazy-init) singletons.36                 finishBeanFactoryInitialization(beanFactory);37 38                 // Last step: publish corresponding event.39                 finishRefresh();40             }41 42             catch (BeansException ex) {43                 if (logger.isWarnEnabled()) {44                     logger.warn("Exception encountered during context initialization - " +45                             "cancelling refresh attempt: " + ex);46                 }47 48                 // Destroy already created singletons to avoid dangling resources.49                 destroyBeans();50 51                 // Reset 'active' flag.52                 cancelRefresh(ex);53 54                 // Propagate exception to caller.55                 throw ex;56             }57 58             finally {59                 // Reset common introspection caches in Spring's core, since we60                 // might not ever need metadata for singleton beans anymore...61                 resetCommonCaches();62             }63         }64     }

后续文章根据以上标出来的每一个加载步骤进行解析。

转载于:https://www.cnblogs.com/burthughes/p/spring_1.html

你可能感兴趣的文章
Android 状态栏通知Notification、NotificationManager详解
查看>>
如何在Google Map中处理大量标记(ASP.NET)(转)
查看>>
Sublime Text 3中使用正则表达式删除空行
查看>>
UIApplicationDelegate协议
查看>>
再谈iOS 7的手势滑动返回功能
查看>>
Jmeter测试dubbo接口填坑
查看>>
python小练——找出指定目录下小于指定字节的文件,输出到文本文件
查看>>
渐渐磨砺--16年11月封闭总结
查看>>
[zz]GDB调试精粹及使用实例
查看>>
数据库的创建和删除
查看>>
【消息队列MQ】各类MQ比较
查看>>
最简单的三层实例【插入据
查看>>
设计模式学习笔记——Prototype原型模式
查看>>
pom.xml里有红叉报错的解决办法
查看>>
Perl last和next的用法区别
查看>>
Selenium 管理 Cookies
查看>>
ZOJ 1204 一个集合能组成多少个等式
查看>>
exceptionfunction[LeetCode]Permutations
查看>>
开始学习iOS开发
查看>>
从int 3探索Windows应用程序调试原理
查看>>