Spring PropertySources 与 PropertySource

org.springframework.core.env.PropertySources 是多个 org.springframework.core.env.PropertySource 的集合,是 spring 管理和保存属性配置的关键接口。
SpringBoot 在启动时,会通过 PropertySourcesPlaceholderConfigurer 装载 PropertySources,往 PropertySources 中放两个对象:environmentProperties 和 localProperties。

environmentProperties 的 environment 配置源中存放着各种 PropertySource,例如:

SystemEnvironmentPropertySource
PropertiesPropertySource
CommandLineProperySource
ResourcePropertySource
ServletContextPropertySource
RandomValuePropertySource
......

org.springframework.core.env.Environment :Environment 对象的作用是为用户提供一个方便的服务接口,用于配置属性源并从中解析属性。

Spring 中将配置源抽象成 org.springframework.core.env.PropertySource 对象,PropertySource 是属性配置源的抽象基类

配置生效顺序

原文地址:https://www.cnblogs.com/kevin-yuan/p/13383584.html