spring-cloud environment
2021-08-17 10:47:01 0 举报
spring-cloud Environment 整体流程源码详解
作者其他创作
大纲/内容
org.springframework.boot.autoconfigure.BackgroundPreinitializerorg.springframework.boot.ClearCachesApplicationListenerorg.springframework.boot.builder.ParentContextCloserApplicationListenerorg.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessororg.springframework.boot.context.FileEncodingApplicationListenerorg.springframework.boot.context.config.AnsiOutputApplicationListenerorg.springframework.boot.context.config.ConfigFileApplicationListenerorg.springframework.boot.context.config.DelegatingApplicationListenerorg.springframework.boot.context.logging.ClasspathLoggingApplicationListenerorg.springframework.boot.context.logging.LoggingApplicationListenerorg.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListenerorg.springframework.cloud.bootstrap.BootstrapApplicationListenerorg.springframework.cloud.bootstrap.LoggingSystemShutdownListenerorg.springframework.cloud.context.restart.RestartListener
主要加载 bootstrap.yaml、application.yaml
applyInitializers(context)
new SpringApplication(primarySources)
org.springframework.cloud.bootstrap.BootstrapApplicationListener#onApplicationEvent
ConfigServicePropertySourceLocator#locate
locator.locateCollection(environment)
@Import(BootstrapImportSelector.class)
url + path = http://<server>/{name}/{profile}/{label}
SpringApplication#run(java.lang.String...)
com.shuidihuzhu.infra.boot.core.feign.LoadFeignClassApplicationContextInitializerorg.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializerorg.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListenerorg.springframework.boot.context.ConfigurationWarningsApplicationContextInitializerorg.springframework.boot.context.ContextIdApplicationContextInitializerorg.springframework.boot.context.config.DelegatingApplicationContextInitializerorg.springframework.boot.web.context.ServerPortInfoApplicationContextInitializercom.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializercom.shuidihuzhu.infra.metadata.starter.configuration.HealthCheckInitializer
ApolloApplicationContextInitializer#initialize
Config config = ConfigService.getConfig(namespace)
ConfigurableEnvironment environment = getOrCreateEnvironment()
setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class))
ConfigFileApplicationListener
spring cloud 父容器 装载在 spring.factories 配置的 xxx.yyy.BootstrapConfiguration 指定的 bean.例如org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfigurationorg.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfigurationorg.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfigurationorg.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfigurationorg.springframework.cloud.config.client.ConfigServiceBootstrapConfigurationorg.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfigurationorg.springframework.cloud.consul.discovery.configclient.ConsulDiscoveryClientConfigServiceBootstrapConfiguration
builder.sources(BootstrapImportSelectorConfiguration.class);
PropertySourceBootstrapConfiguration#initialize
application.addInitializers(new AncestorInitializer(context))
final ConfigurableApplicationContext context = builder.run()
listeners.environmentPrepared(environment)
Environment
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class))
createSpringFactoriesInstances
ConfigServicePropertySourceLocator#getRemoteEnvironment
SpringApplicationBuilder builder = new SpringApplicationBuilder()
AbstractEnvironment
org.springframework.boot.env.YamlPropertySourceLoader#load
public static final String IGNORE_GETENV_PROPERTY_NAME = \"spring.getenv.ignore\";public static final String ACTIVE_PROFILES_PROPERTY_NAME = \"spring.profiles.active\";public static final String DEFAULT_PROFILES_PROPERTY_NAME = \"spring.profiles.default\";protected static final String RESERVED_DEFAULT_PROFILE_NAME = \"default\";private final Set<String> activeProfiles = new LinkedHashSet<>();private final Set<String> defaultProfiles = new LinkedHashSet<>(getReservedDefaultProfiles());private final MutablePropertySources propertySources = new MutablePropertySources();private final ConfigurablePropertyResolver propertyResolver = new PropertySourcesPropertyResolver(this.propertySources);
0 条评论
下一页