前言-阅读源码有利于陶冶情操,本文承接前文Spring源码情操陶冶-ContextLoader

约束:本文指定contextClass为默认的XmlWebApplicationContext

AbstractApplicationContext#refresh()

简单看下refresh()方法内罗列的一系列方法,代码清单如下

public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
// Prepare this context for refreshing.
prepareRefresh(); // Tell the subclass to refresh the internal bean factory.
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context.
prepareBeanFactory(beanFactory); try {
// Allows post-processing of the bean factory in context subclasses.
postProcessBeanFactory(beanFactory); // Invoke factory processors registered as beans in the context.
invokeBeanFactoryPostProcessors(beanFactory); // Register bean processors that intercept bean creation.
registerBeanPostProcessors(beanFactory); // Initialize message source for this context.
initMessageSource(); // Initialize event multicaster for this context.
initApplicationEventMulticaster(); // Initialize other special beans in specific context subclasses.
onRefresh(); // Check for listener beans and register them.
registerListeners(); // Instantiate all remaining (non-lazy-init) singletons.
finishBeanFactoryInitialization(beanFactory); // Last step: publish corresponding event.
finishRefresh();
} catch (BeansException ex) {
// Destroy already created singletons to avoid dangling resources.
destroyBeans(); // Reset 'active' flag.
cancelRefresh(ex); // Propagate exception to caller.
throw ex;
}
}
}

针对上述的代码逻辑,为了避免代码的凌乱以及放在同篇文章文字过长,遂作如下链接导航

  • AbstractApplicationContext#prepareRefresh

    刷新准备工作,@prepareRefresh

  • AbstractApplicationContext#obtainFreshBeanFactory

    涉及解析spring配置文件并封装为BeanDefinition对象保存至beanFactory中,@obtainFreshBeanFactory

  • AbstractApplicationContext#prepareBeanFactory

    beanFactory的准备工作,设置context的属性配置,@prepareBeanFactory

  • AbstractApplicationContext#postProcessBeanFactory

    主要添加ServletContextAwareProcessor处理类,@postProcessBeanFactory

  • AbstractApplicationContext#invokeBeanFactoryPostProcessors

    执行BeanDefinitionRegistryPostProcessors/BeanFactoryPostProcessors相关beans,@invokeBeanFactoryPostProcessors

  • AbstractApplicationContext#registerBeanPostProcessors

    注册所有实现BeanPostProcessor的接口bean到beanFactory的内部属性beanPostProcessors集合中,@registerBeanPostProcessors

  • AbstractApplicationContext#initMessageSource

    初始化资源配置,@initMessageSource

  • AbstractApplicationContext#initApplicationEventMulticaster

    初始化ApplictionEventMulticaster广播事件类,@initApplicationEventMulticaster

  • AbstractApplicationContext#onRefresh

    初始化themeSource,@onRefresh

  • AbstractApplicationContext#registerListeners

    注册ApplicationListener beans到ApplictionEventMulticaster广播集合,@registerListeners

  • AbstractApplicationContext#finishBeanFactoryInitialization

    实例化所有的非lazy-init类型的beans,@finishBeanFactoryInitialization

  • AbstractApplicationContext#finishRefresh

    完成刷新,并执行ContextRefreshedEvent事件,该事件涉及spring mvc,@finishRefresh

结束语

阅读源码的目的是为了了解其运行的机制,但可能涵盖的内容过广,可以对有兴趣的地方进行深刻的源码追踪,并理解其中的代码设计,不为是一件快乐的事情

Spring源码情操陶冶-AbstractApplicationContext的更多相关文章

  1. Spring源码情操陶冶-AbstractApplicationContext#finishBeanFactoryInitialization

    承接前文Spring源码情操陶冶-AbstractApplicationContext#registerListeners 约定web.xml配置的contextClass为默认值XmlWebAppl ...

  2. Spring源码情操陶冶-AbstractApplicationContext#registerListeners

    承接前文Spring源码情操陶冶-AbstractApplicationContext#onRefresh 约定web.xml配置的contextClass为默认值XmlWebApplicationC ...

  3. Spring源码情操陶冶-AbstractApplicationContext#onRefresh

    承接前文Spring源码情操陶冶-AbstractApplicationContext#initApplicationEventMulticaster 约定web.xml配置的contextClass ...

  4. Spring源码情操陶冶-AbstractApplicationContext#initApplicationEventMulticaster

    承接前文Spring源码情操陶冶-AbstractApplicationContext#initMessageSource 约定web.xml配置的contextClass为默认值XmlWebAppl ...

  5. Spring源码情操陶冶-AbstractApplicationContext#initMessageSource

    承接前文Spring源码情操陶冶-AbstractApplicationContext#registerBeanPostProcessors 约定web.xml配置的contextClass为默认值X ...

  6. Spring源码情操陶冶-AbstractApplicationContext#registerBeanPostProcessors

    承接前文Spring源码情操陶冶-AbstractApplicationContext#invokeBeanFactoryPostProcessors 瞧瞧官方注释 /** * Instantiate ...

  7. Spring源码情操陶冶-AbstractApplicationContext#invokeBeanFactoryPostProcessors

    阅读源码有利于陶冶情操,承接前文Spring源码情操陶冶-AbstractApplicationContext#postProcessBeanFactory 约定:web.xml中配置的context ...

  8. Spring源码情操陶冶-AbstractApplicationContext#postProcessBeanFactory

    阅读源码有利于陶冶情操,承接前文Spring源码情操陶冶-AbstractApplicationContext#prepareBeanFactory 约定:web.xml中配置的contextClas ...

  9. Spring源码情操陶冶-AbstractApplicationContext#prepareBeanFactory

    阅读源码有助于陶冶情操,本文承接Spring源码情操陶冶-AbstractApplicationContext#obtainFreshBeanFactory 瞧瞧官方注释 /** * Configur ...

  10. Spring源码情操陶冶-AbstractApplicationContext#obtainFreshBeanFactory

    前言-阅读源码有利于陶冶情操,本文承接前文Spring源码情操陶冶-AbstractApplicationContext 约束: 本文指定contextClass为默认的XmlWebApplicati ...

随机推荐

  1. JS实现AOP拦截方法调用

    //JS实现AOP拦截方法调用function jsAOP(obj,handlers) {    if(typeof obj == 'function'){        obj = obj.prot ...

  2. Centos常用命令及解释

    ps -ef|grep java ps:将某个进程显示出来-A 显示所有程序. -e 此参数的效果和指定"A"参数相同.-f 显示UID,PPIP,C与STIME栏位. grep命 ...

  3. AWS Organizations

    AWS Organizations offers policy-based management for multiple AWS accounts and is now generally avai ...

  4. 转化来的图标用法symbol引用‘font-class引用及Unicode引用

  5. 如何用VMware打开vmdk文件

    vmdk文件是一个虚拟机备份文件!你可以在vmware新建一个任何类型的虚拟机,命名为“test”,在“我的文档”找到vmware的虚拟机目录“test”,在"test"目录中可以 ...

  6. 【LeetCode】160. Intersection of Two Linked Lists

    题目: Write a program to find the node at which the intersection of two singly linked lists begins. Fo ...

  7. 【Android Developers Training】 49. 轻松录制视频

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  8. c# MySqlHelper_ExecuteSqlTran

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Text;u ...

  9. RabbitMQ系列教程之五:主题(Topic)

    (本实例都是使用的Net的客户端,使用C#编写),说明,中文方括号[]表示名词.   在上一个教程中,我们改进了我们的日志记录系统. 没有使用只能够进行虚拟广播的[Fanout]交换机,而是使用了[D ...

  10. diy toy: image auto-handler

    备忘之:) config.xml <?xml version="1.0" encoding="utf-8"?> <config> < ...