SpringBoot 2.5 自动装配源码分析
从 SpringApplicaton.run 方法开始

属性: bootstrapRegistryInitializers

jar包 中的 spring.factories

根据加载的列表获取实例

排序

属性: listeners
流程同上
属性: mainApplicationClass
获取main方法所在的类
for(int var4 = 0; var4 < var3; ++var4) { StackTraceElement stackTraceElement = var2[var4]; if ("main".equals(stackTraceElement.getMethodName())) { return Class.forName(stackTraceElement.getClassName()); } }
run 方法
stopWatch 计时
StopWatch stopWatch = new StopWatch(); stopWatch.start();
创建启动上下文
DefaultBootstrapContext bootstrapContext = new DefaultBootstrapContext();
this.bootstrapRegistryInitializers.forEach((initializer) -> {
initializer.initialize(bootstrapContext)
});
return bootstrapContext;
创建监听器
Class<?>[] types = new Class[]{SpringApplication.class, String[].class};
return new SpringApplicationRunListeners(logger, this.getSpringFactoriesInstances(SpringApplicationRunListener.class, types, this, args), this.applicationStartup);
开启监听
listeners.starting(bootstrapContext, this.mainApplicationClass);
待续
论读书
睁开眼,书在面前 闭上眼,书在心里
睁开眼,书在面前 闭上眼,书在心里

浙公网安备 33010602011771号