首页 > 数据库 > 数据库开发技术 > springboot启动流程分析
之前梳理的springboot的启动流程,大家想了解的可以看下。
整个springboot启动的流程,更像是一个大的模板方法。
在模板中的每个节点去产生一些具体的事件。
springboot在构造的时候就把Listener都拿到了,这些事件触达以后,对应的listener就自动执行。
是整个流程启动的口子。
@SpringBootApplication
public class Starter {
public static void main(String[] args) {
SpringApplication.run(Starter.class,args);
//new SpringApplication(Starter.class).run(args);
}
}在这里,主要有两点:
1, 构造函数,构造函数主要是为了准备一些
2,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));//推断出应用程序是reactive、servlet,还是非web应用this.webApplicationType = WebApplicationType.deduceFromClasspath();setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));this.mainApplicationClass = deduceMainApplicationClass();}

getSpringFactoriesInstances 流程
加载所有包的中的spring.factories 把对应的Listener等都拿到






原文作者:5ycode;如有侵权,请联系管理员删除。