SpringBoot自动配置原理
前言:这篇文章是在看完SpringBoot自动配置原理后记录的,如果有不对的地方烦请多多指正。
SpringBoot应用启动流程
通过调用追踪,我们发现SpringBoot应用启动时,它做了两件事:创建SpringApplication对象、运行run方法,源代码如下:
public static ConfigurableApplicationContext run(Class<?>[] primarySources, String[] args) {
return (new SpringApplication(primarySources)).run(args);
}
我们接着来看,这两步,主要干了些啥。
- 创建SpringApplication对象
public SpringApplication(Class<?>... primarySources) {
this((ResourceLoader)null, primarySources);
}
public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
this.sources = new LinkedHashSet();
this.bannerMode = Mode.CONSOLE;
this.logStartupInfo = true;
this.addCommandLineProperties = true;
this.addConversionService = true;
this.headless = true;
this.registerShutdownHook = true;
this.additionalProfiles = new HashSet();
this.isCustomEnvironment = false;
this.lazyInitialization = false;
this