AbstractApplicationContext 分析

启动流程
// Prepare this context for refreshing.
prepareRefresh();
1.
// Initialize any placeholder property sources in the context environment
//预处理配置,目前看到WEB层实现(预处理WEB配置)
initPropertySources();

2. // Validate that all properties marked as required are resolvable
// see ConfigurablePropertyResolver#setRequiredProperties
//验证系统配置
getEnvironment().validateRequiredProperties();

// Tell the subclass to refresh the internal bean factory.
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();

// Prepare the bean factory for use in this context.
//预处理beanFactory
prepareBeanFactory(beanFactory);

try {
// Allows post-processing of the bean factory in context subclasses.
//预处理beanFactory之后 后期处理 目前也看到只有WEB实现(注册相关依赖)
postProcessBeanFactory(beanFactory);

// Invoke factory processors registered as beans in the context.
//执行beanFactory后期处理
invokeBeanFactoryPostProcessors(beanFactory);
//处理流程优先级(本身实例不考虑)
1.BeanDefinitionRegistryPostProcessor
2.BeanFactoryPostProcessor
3.BeanFactoryPostProcessor(插件处理) priorityOrdered -> ordered ->nonOrdered

// Register bean processors that intercept bean creation.
//注册后期处理器 (扫描接口 BeanPostProcessor)
registerBeanPostProcessors(beanFactory);
//执行优先级 PriorityOrdered -> ordered -> nonOrdered

// Initialize message source for this context.
//初始化 国际化对象
initMessageSource();

// Initialize event multicaster for this context.
//初始化事件广播对象
initApplicationEventMulticaster();

// Initialize other special beans in specific context subclasses.
//完成处理后期后,刷新 目前也只看到web跟 DefaultLifecycleProcessor 实现
onRefresh();

// Check for listener beans and register them.
//注册处理spring 事件 优先级本身实例事件 -> 扫描所有 spring 事件接口对象
registerListeners();

// Instantiate all remaining (non-lazy-init) singletons.
//初始化完成 beanFactory 处理器
finishBeanFactoryInitialization(beanFactory);

// Last step: publish corresponding event.
//完成beanFactory容器处理
finishRefresh();
1.initLifecycleProcessor();//初始化生命周期处理器
2.getLifecycleProcessor().onRefresh();//刷新生命周期处理器
3.publishEvent(new ContextRefreshedEvent(this)); //发布ContextRefreshedEvent事件
4.registerApplicationContext();//注册上下文

关闭容器事件
1.Runtime.getRuntime().removeShutdownHook(this.shutdownHook); //移动JVM线程级监控
2.LiveBeansView.unregisterApplicationContext(this);//清空上下文 unregisterMBean
3.publishEvent(new ContextClosedEvent(this)); //发布关闭事件
4.getLifecycleProcessor().onClose();
5.destroyBeans()//没看到有实现
6.closeBeanFactory();//删除BEAN
7.// Let subclasses do some final clean-up if they wish...
onClose()

小结 :
1.预处理后注入相关依赖 实现 BeanFactoryPostProcessor
2.预处理后修改bean 实现 BeanPostProcessor
3.完成预处理后执行 实现 DefaultLifecycleProcessor

4.完成整个加载后执行 实现 ApplicationListener ContextRefreshedEvent 事件

5.关闭并且在销毁之前 实现 DefaultLifecycleProcessor 或 ApplicationListener ContextClosedEvent 事件

FactoryBean,AbstractFactoryBean<T> ,InitializingBean ,DisposableBean,BeanFactoryAware

spring 启动流程的更多相关文章

  1. Spring启动流程—源码解读

    https://blog.csdn.net/yangliuhbhd/article/details/80790761 Spring的AbstractApplicationContext的refresh ...

  2. Spring启动流程

    首先,对于一个web应用,其部署在web容器中,web容器提供其一个全局的上下文环境,这个上下文就是ServletContext,其为后面的spring IoC容器提供宿主环境: 其次,在web.xm ...

  3. Spring Boot启动流程详解(一)

    环境 本文基于Spring Boot版本1.3.3, 使用了spring-boot-starter-web. 配置完成后,编写了代码如下: @SpringBootApplication public ...

  4. activiti自定义流程之Spring整合activiti-modeler5.16实例(六):启动流程

    注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建        (2)创建流程模型:activiti自定义流程之Spring ...

  5. Spring基础系列-容器启动流程(1)

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9870339.html 概述 ​ 我说的容器启动流程涉及两种情况,SSM开发模式和Spri ...

  6. Spring基础系列-容器启动流程(2)

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9503210.html 一.概述 这里是Springboot项目启动大概流程,区别于SSM ...

  7. Spring启动过程分析】(1)启动流程简介

    1. spring简介 spring的最基本的功能就是创建对象及管理这些对象之间的依赖关系,实现低耦合.高内聚.还提供像通用日志记录.性能统计.安全控制.异常处理等面向切面的能力,还能帮我们管理最头疼 ...

  8. Spring Boot启动流程详解

    注:本文转自http://zhaox.github.io/java/2016/03/22/spring-boot-start-flow 环境 本文基于Spring Boot版本1.3.3, 使用了sp ...

  9. Spring启动执行流程梳理

    注:本文梳理启动流程使用的Spring版本:4.0.2.RELEASE 使用spring配置,都需要在web.xml中配置一个spring的监听器和启动参数(context-param),如下: &l ...

随机推荐

  1. 【转】关于KDD Cup '99 数据集的警告,希望从事相关工作的伙伴注意

    Features From: Terry Brugger Date: 15 Sep 2007 Subject: KDD Cup '99 dataset (Network Intrusion) cons ...

  2. atitit.web ui 结构建模工具总结

    atitit.web ui 结构建模工具总结 1. 王者.dreamweaver 1 2. Frontpage/SharePoint Designer(FrontPage) 2010... 1 3.  ...

  3. JavaScript-分支语句与函数

    一.分支语句-if语句 四种if语句: 1.if(判断条件) { 满足条件时需执行的语句 } 2.if(判断条件) { 满足条件时需执行的语句 } else { 不满足条件时需执行的语句 } 3.if ...

  4. iOS开发之静态库(一)—— 基本概念

    在项目开发过程中,经常出现优秀代码重用现象,又或者提供给第三方功能模块却又不想让其看到源代码,这些时候,通常的做法是将代码封装成库或者框架,这些在Windows编程或Linux编程中非常容易实现的过程 ...

  5. iOS开发-【C语言】三目运算符

    1.N目运算符 像逻辑非(!).负号(-)这种只连接一个数据的符号,称为“单目运算符”,比如!5.-5.像算术运算符.关系运算符.逻辑运算符这种连接二个数据的负号,称为“双目运算符”,比如6+7.8* ...

  6. Android 学习之显式激活与隐式激活Activity

    在res界面里面有两个布局文件activity_main和acivity_two

  7. android: startActivityForResult用法详解

    一.如果想在Activity中得到新打开Activity 关闭后返回的数据,需要使用系统提供的startActivityForResult(Intent intent, int requestCode ...

  8. Quartz 2.2.x CronTrigger Tutorial

    http://www.quartz-scheduler.org/documentation/quartz-2.2.x/tutorials/crontrigger.html Introduction c ...

  9. Android 中的AIDL,Parcelable和远程服务

    Android 中的AIDL,Parcelable和远程服务      早期在学习期间便接触到AIDL,当时对此的运用也是一撇而过.只到近日在项目中接触到AIDL,才开始仔细深入.AIDL的作用    ...

  10. [界面开发新秀]AYUI开发360领航版系列教程-AyWindow接入[1/40]

    开发包DLL下载地址:请加入 466717219群,自己下载(已经发布ayui3.7,在群里,为了不让你作为收藏工具,也只有入群才能下载,喜欢你就进.不喜欢你还是不要来了) AYUI初衷:简单化商业软 ...