1.Sort ApplicationInitializer:
2.sort Listener:
3.getRunListener:
4.eventPublishingRunListener.starting 发布启动中事件;
构建 ApplicationArguments 参数,
4.1prepareEnvement:
[StubPropertySource {name='servletConfigInitParams'},
StubPropertySource {name='servletContextInitParams'},
PropertiesPropertySource {name='systemProperties'},
SystemEnvironmentPropertySource {name='systemEnvironment'}]
5.eventPublistRunlistener.environmentPrepared (环境变量) 发布环境已经准备好了的事件:
propertySources:[
ConfigurationPropertySourcesPropertySource {name='configurationProperties'},
StubPropertySource {name='servletConfigInitParams'},
StubPropertySource {name='servletContextInitParams'},
PropertiesPropertySource {name='systemProperties'},
SystemEnvironmentPropertySource {name='systemEnvironment'}]
最后返回的environment如下:
[ConfigurationPropertySourcesPropertySource {name='configurationProperties'},
MapPropertySource {name='bootstrap'},
PropertiesPropertySource {name='systemProperties'},
OriginAwareSystemEnvironmentPropertySource {name='systemEnvironment'}, RandomValuePropertySource {name='random'},
MapPropertySource {name='springCloudClientHostInfo'},
OriginTrackedMapPropertySource {name='applicationConfig: [classpath:/bootstrap.yml]'}]
6.创建ConfigurableApplicationContext ,这里只是通过构造函数创建一个基本对象
7.prepareContext 准备容器内容 ,入参(ConfigurableApplicationContext context, ConfigurableEnvironment environment, SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments, Banner printedBanner)
其中包括BootstrapImportSelectorConfiguration
这里重点是将spring.factories中的BootstrapConfiguration和环境中配置的spring.cloud.bootstrap.sources 进行合并,然后排序,然后返回。。相当于给容器中注入了bean![截屏2024-11-29 00.34.58]
protected void load(ApplicationContext context, Object[] sources) {
if (logger.isDebugEnabled()) {
logger.debug("Loading source " + StringUtils.arrayToCommaDelimitedString(sources));
}
BeanDefinitionLoader loader = this.createBeanDefinitionLoader(this.getBeanDefinitionRegistry(context), sources);
if (this.beanNameGenerator != null) {
loader.setBeanNameGenerator(this.beanNameGenerator);
}
if (this.resourceLoader != null) {
loader.setResourceLoader(this.resourceLoader);
}
if (this.environment != null) {
loader.setEnvironment(this.environment);
}
loader.load();
}
private int load(Object source) {
Assert.notNull(source, "Source must not be null");
if (source instanceof Class) {
return this.load((Class)source);
} else if (source instanceof Resource) {
return this.load((Resource)source);
} else if (source instanceof Package) {
return this.load((Package)source);
} else if (source instanceof CharSequence) {
return this.load((CharSequence)source);
} else {
throw new IllegalArgumentException("Invalid source type " + source.getClass());
}
}
根据不同的类型进行load,其中包括Class的register、Package 的scan 、Resource的loadBeanDefinitions;总之重写了很多的类型。
DefaultListableBeanFactory
标签:load,springboot,sources,流程,environment,source,context,完整版,name From: https://www.cnblogs.com/euler-blog/p/18616019