题外话
因工作原因,陆续开始接触spring boot,且对其源码和机制越来越发的需要深入了解。所以想系统的分析下spring boot源码,希望可以坚持下去。
spring boot启动
@SpringBootApplication
public class SimpleApplication {
public static void main(String[] args) {
SpringApplication.run(SimpleApplication.class, args);
}
}
从最简化的spring boot启动main入口中可以看出通过SpringApplication.run(Class, String[])方法启动的。我们跟进入方法,不难发现run静态方法中构造了SpringApplication对象,然后进行run方法。
首先查看主构造方法:
public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
this.resourceLoader = resourceLoader;
Assert.notNull(primarySources, "PrimarySources must not be null");
this.primarySources = new LinkedHashSet<>(Arrays.asList(primarySources));
this.webApplicationType = WebApplicationType.deduceFromClasspath();
setInitializers((Collection) getSpringFactoriesInstances(
A