spring boot 源码解析 启动流程
2020-12-13 05:50
标签:ati UNC types port strong string rgs event app 在面试过程中经常被问到过spring boot的启动流程,今天就翻一下源码整体看一下; 首先,新建一个启动类,可以看到是首先调用的SpringApplication的静态方法run 负责启动SpringBoot的主要方法 整个启动流程大体就是这样,先有一个整体的概念,其中实现细节很庞杂,后续逐一研究 spring boot 源码解析 启动流程 标签:ati UNC types port strong string rgs event app 原文地址:https://www.cnblogs.com/NealRiver/p/11150367.htmlspring boot 源码解析 启动流程
@SpringBootApplication
public class SourceReadApplillcation {
public static void main(String[] args) {
SpringApplication.run(SourceReadApplillcation.class,args);
}
}
public static ConfigurableApplicationContext run(Class> primarySource,
String... args) {
return run(new Class>[] { primarySource }, args);
}
public static ConfigurableApplicationContext run(Class>[] primarySources,
String[] args) {
return new SpringApplication(primarySources).run(args);
}
public SpringApplication(Class>... primarySources) {
this(null, primarySources);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public SpringApplication(ResourceLoader resourceLoader, Class>... primarySources) {
this.resourceLoader = resourceLoader;
Assert.notNull(primarySources, "PrimarySources must not be null");
this.primarySources = new LinkedHashSet(Arrays.asList(primarySources));
//推断web应用类型;
this.webApplicationType = WebApplicationType.deduceFromClasspath();
//设置初始化器,从META-INF/spring.factories读取ApplicationContextInitializer
//配置的值,读取详情后续研究
setInitializers((Collection) getSpringFactoriesInstances(
ApplicationContextInitializer.class));
//设置监听器,同上,读取ApplicationListener配置的值
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
//设置应用main启动类
this.mainApplicationClass = deduceMainApplicationClass();
}
public ConfigurableApplicationContext run(String... args) {
//计时器,主要为了统计消耗时间
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//初始化应用上下文和异常报告集合
ConfigurableApplicationContext context = null;
Collection