首页  

SpringBoot启动过程简介     所属分类 springboot 浏览量 840
SpringApplicaiton初始化
确定ApplicationContext类型 (Web Reactive Standard))
加载ApplicationContextInitializer (在刷新context之前执行)
加载ApplicationListener
Environment初始化
解析命令行参数
创建Environment
配置Environment
配置SpringApplication
ApplicationContext初始化
创建ApplicationContext
设置ApplicationContext
刷新ApplicationContext
执行ApplicationRunner和CommandLineRunner


spring.factories
classpath:/META-INF/spring.factories

SpringFactoriesLoader


spring-boot-2.2.0.RELEASE.jar  里的 spring.factories

# PropertySource Loaders
org.springframework.boot.env.PropertySourceLoader=\
org.springframework.boot.env.PropertiesPropertySourceLoader,\
org.springframework.boot.env.YamlPropertySourceLoader

键值对
key是完整接口名
value是key的实现类
spring.factories由SpringFactoriesLoader工具类加载
spring.factories位于classpath:/META-INF/目录
SpringFactoriesLoader会加载jar包里面的spring.factories文件并进行合并



ApplicationContextInitializer 实现初始化工作

org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\
org.springframework.boot.context.ContextIdApplicationContextInitializer,\
org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\
org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer,\
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer

ApplicationListener

# Application Listeners
org.springframework.context.ApplicationListener=\
org.springframework.boot.ClearCachesApplicationListener,\
org.springframework.boot.builder.ParentContextCloserApplicationListener,\
org.springframework.boot.context.FileEncodingApplicationListener,\
org.springframework.boot.context.config.AnsiOutputApplicationListener,\
org.springframework.boot.context.config.ConfigFileApplicationListener,\
org.springframework.boot.context.config.DelegatingApplicationListener,\
org.springframework.boot.context.logging.ClasspathLoggingApplicationListener,\
org.springframework.boot.context.logging.LoggingApplicationListener


Environment初始化
解析命令行参数
准备环境(Environment)
设置环境


SpringApplicaton属性设置

环境变量
命令行参数
JVM系统属性

刷新ApplicationContext


准备刷新(验证属性、设置监听器)
初始化BeanFactory
执行BeanFactoryPostProcessor
注册BeanPostProcessor
初始化MessageSource
初始化事件广播
注册ApplicationListener

执行ApplicationRunner和CommandLineRunner

上一篇     下一篇
基于 ReentrantLock Condition await signalAll 实现简单的阻塞队列

Synchronized 和 AQS 实现要点

java死锁实例

Springboot2 Tomcat自定义配置

springboot2 FileEncodingApplicationListener简介

maven jar包冲突处理