springboot
2019-07-24 17:49:52 0 举报
springboot 启动流程流
作者其他创作
大纲/内容
deduceMainApplicationClass()
implements
1、实例化SpringApplicationRunListener接口实现类
getRunListeners().starting()
configureHeadlessProperty
CloudFoundryVcapEnvironmentPostProcessor
异步调用onApplicationEvent
EventPublishingRunListener构造函数 this.initialMulticaster = new SimpleApplicationEventMulticaster(); //获取ApplicationListener实现类列表listeners,add所有的listener到init
ConfigurableApplicationContext run(String... args)
createApplicationContext
loader()加载所有PropertySourceLoader实现类
方法
setListeners(Collection<? extends ApplicationListener<?>> listeners)设置将应用于SpringApplication并在ApplicationContext中注册的ApplicationListener。
SimpleApplicationEventMulticaster
SpringApplicationJsonEnvironmentPostProcessor
listeners=ApplicationListener.class
ApplicationContextInitializer所有实现类
SpringApplicationEvent
调用广播事件方法
2、执行starting
interface SpringApplicationRunListenerstarting()environmentPrepared(ConfigurableEnvironment environment)()running(ConfigurableApplicationContext context)started(ConfigurableApplicationContext context)
multicastEvent(ApplicationEvent event)
extents
调用SpringFactoriesLoader.loadFactories 加载并实例化EnvironmentPostProcessor实现类添加当前对象到加载列表
PropertiesPropertySourceLoader
deduceWebApplicationType()
class ConfigurationWarningsApplicationContextInitializer\t\timplements ApplicationContextInitializer<ConfigurableApplicationContext>
extends
setInitializers(Collection<? extends ApplicationContextInitializer<?>> initializers)设置将应用于SpringApplicationContext的ApplicationContextInitiator
new
onApplicationEvent
getSpringFactoriesInstances(Class<T> type)根据给定接口类,获取配置文件中的所有需要接口并实例化这些实现类
EnvironmentPostProcessorpostProcessEnvironment()
applyInitializers(ConfigurableApplicationContext context)initializer.initialize(context);将初始化时的ApplicationContextInitializer实例initializers列表迭代设置初始化context
调用
1、加载所有接口实现类2、调用postProcessEnvironment
class Loader 加载候选配置文件并配置有效配置
ApplicationListener实现类
ConfigurableApplicationContext
printBanner(ConfigurableEnvironment environment)
interface ApplicationListener<E extends ApplicationEvent> extends EventListenervoid onApplicationEvent(E event);//处理application event
postProcessEnvironment实现方法new Load().load()
interface Orderedint getOrder();//获取当前对象的序号
contextClass=Class.forName(AnnotationConfigServletWebServerApplicationContext)contextClass=Class.forName(AnnotationConfigReactiveWebServerApplicationContext)contextClass=Class.forName(AnnotationConfigApplicationContext)BeanUtils.instantiateClass(contextClass)
interface PropertySourceLoaderload()
onApplicationEnvironmentPreparedEvent
SystemEnvironmentPropertySourceEnvironmentPostProcessor
EventListener
context=createApplicationContext()
interface ApplicationContextInitializer<C extends ConfigurableApplicationContext>void initialize(C applicationContext);//初始化给定的application context
exceptionReporters=SpringBootExceptionReporter
class ConfigFileApplicationListener 处理配置文件类
ClearCachesApplicationListener implements ApplicationListener<ContextRefreshedEvent>
class SpringApplication
配置环境调用
所有实现类
initializers=ApplicationContextInitializer.class
class SpringFactoriesLoader
SpringApplicationRunListener
YamlPropertySourceLoader
loadSpringFactories(@Nullable ClassLoader classLoader) 加载META-INF/spring.factories文件
收藏
收藏
0 条评论
下一页