初始化SpringApplication:getSpringFactoriesInstances获取BootstrapRegistryInitializer、ApplicationContextInitializer、ApplicationListener;发布SpringApplicationRunListeners#starting事件初始化执行Environment:初始化类型为ApplicationServletEnvironment的Environment(初始化MutablePropertySources:包括servletContextInitParams(ServletContext)、servletConfigInitParams(ServletConfig)、jndiProperties、systemEnvironment(System.getenv()),systemProperties(System.getProperties())初始化ApplicationConversionService),并将startupargs作为PropertySource添加到MutablePropertySources中,然后将所有PropertySources封装到SpringConfigurationPropertySources中(通过SpringConfigurationPropertySource.from转换而来,使用PropertyMapper映射PropertySource和ConfigurationPropertySource字段名的关系,比如将下划线改为大写字母,处理'.''-'等符号)然后发布SpringApplicationRunListeners#environmentPrepared事件,(springboot上下文加载过程)用监听器BootstrapApplicationListener监听该事件,会判断是否spring.cloud.bootstrap.enabled属性继续执行,创建SpringBoot自己的引导上下文BootstrapContext,并将创建的上下文设置为父上下文;StandardEnvironment将在父上下文中创建,然后MutablePropertySources将被清空,并添加一个引导程序PropertySource。添加主上下文的PropertySource后,会构建上下文(web类型为NONE,所以BootstrapContext初始化不会启动tomcat,同时会注入一个BootstrapImportSelectorConfiguration,用于扫描BootstrapConfiguration注解的配置类会在BootstrapContext启动时执行),BootstrapContext构建完成后会进行初始化。构造的上下文类型为AnnotationConfigApplicationContext。在执行过程中,environmentPrepared阶段会执行并释放ApplicationEnvironmentPreparedEvent事件,其中EnvironmentPostProcessorApplicationListener接受处理事件并获取所有EnvironmentPostProcessor类型的处理或添加Environment的PropertySource(包括json的处理,随机数的处理,springCloudClientHostInfo新的PropertySource,bootstrap.yml的加载和spring.cloud.config的处理ConfigDataEnvironmentPostProcessor等)ConfigDataEnvironmentPostProcessor这里ConfigDataLocationResolver先找到匹配的file:./file:./config/file:./config/*/,然后匹配classpath:/classpath:/config/bootcontext启动后,主要context在ApplicationEnvironmentPreparedEvent事件回调ConfigFileApplicationListener中加载application*.yml,构造context的类型为AnnotationConfigServletWebServerApplicationContext,prepareContext准备过程中,执行Initializers回调(PropertySourceBootstrapConfiguration通过PropertySourceLocator加载PropertySource(springcloud提供的接口,nacos实现规范读取和设置配置))
