SpringBoot 启动流程 (2)

Source 继承自 SimpleCommandLinePropertySource,用于解析简单的命令行参数

public DefaultApplicationArguments(String... args) { Assert.notNull(args, "Args must not be null"); this.source = new Source(args); this.args = args; } 准备 Spring 应用环境 private ConfigurableEnvironment prepareEnvironment(SpringApplicationRunListeners listeners, DefaultBootstrapContext bootstrapContext, ApplicationArguments applicationArguments) { // Create and configure the environment // 创建或者获取应用环境 ConfigurableEnvironment environment = getOrCreateEnvironment(); // 配置应用环境 configureEnvironment(environment, applicationArguments.getSourceArgs()); ConfigurationPropertySources.attach(environment); // listeners 环境准备,广播 ApplicationEnvironmentPreparedEvent listeners.environmentPrepared(bootstrapContext, environment); // 附加配置源 DefaultPropertiesPropertySource.moveToEnd(environment); // 配置其他激活文件 configureAdditionalProfiles(environment); // 将环境绑定给当前应用程序 bindToSpringApplication(environment); if (!this.isCustomEnvironment) { environment = new EnvironmentConverter(getClassLoader()).convertEnvironmentIfNecessary(environment, deduceEnvironmentClass()); } // 配置 propertySource 对它自己的递归依赖 ConfigurationPropertySources.attach(environment); return environment; } 创建 banner 打印类并执行

打印 banner 的详细操作过程

private Banner printBanner(ConfigurableEnvironment environment) { if (this.bannerMode == Banner.Mode.OFF) { return null; } ResourceLoader resourceLoader = (this.resourceLoader != null) ? this.resourceLoader : new DefaultResourceLoader(null); SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(resourceLoader, this.banner); if (this.bannerMode == Mode.LOG) { return bannerPrinter.print(environment, this.mainApplicationClass, logger); } return bannerPrinter.print(environment, this.mainApplicationClass, System.out); } 创建应用上下文

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpydfx.html