Loading

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);

待续

posted @ 2021-12-24 16:28  BigBender  阅读(121)  评论(0)    收藏  举报