SpringBoot启动流程
2021-11-26 16:01:32 0 举报
Spring应用在启动的时候,SpringBoot都帮我们做了哪些事情?通过流程图的形式直观的了解
作者其他创作
大纲/内容
this.resourceLoader = resourceLoader设置资源加载器resourceLoader,本例中为null
this.mainApplicationClass = deduceMainApplicationClass();推断应用引导类
1. 构造SpringApplication实例SpringApplication application = new SpringApplication(MyApplication.class)
setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));加载Spring应用上下文初始化器
ConfigurableApplicationContext context = createApplicationContext();创建Spring应用上下文
DefaultBootstrapContext bootstrapContext = createBootstrapContext();使用bootstrapRegistryInitializers初始化器来初始化启动上下文
refreshContext(context);Spring应用上下文启动阶段
ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);装配applicationArguments,简化Spring应用命令行启动参数
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));加载Spring应用事件监听器
this.webApplicationType = WebApplicationType.deduceFromClasspath();从类路径推断web应用类型,本例中为Servlet
2. 配置Spring应用(可选)
this.bootstrapRegistryInitializers = getBootstrapRegistryInitializersFromSpringFactories();加载Spring应用启动注册初始化器bootstrapRegistryInitializers,在运行阶段用
this.primarySources = new LinkedHashSet<>(Arrays.asList(primarySources));设置主配置类集合primarySources本例中为com.example.springstudy.MyApplication
3. 运行阶段application.run()
收藏
0 条评论
下一页