SpringBoot应用中涉及配置相关的东西,例如配置文件、环境变量、系统变量等都是基于类ApplicationServletEnvironment的构造器开启的,如下其抽象父类AbstractEnvironment构造器:
public abstract class AbstractEnvironment{
private final MutablePropertySources propertySources;
private final ConfigurablePropertyResolver propertyResolver;
public AbstractEnvironment() {
this(new MutablePropertySources());
}
protected AbstractEnvironment(MutablePropertySources propertySources) {
this.propertySources = propertySources;
this.propertyResolver = createPropertyResolver(propertySources);
customizePropertySources(propertySources);
}
}
抽象类PropertySource 内部存在两个属性 name & source:
public abstract class PropertySource<T> {
protected final String name;
protected final T source;
}
其中,泛型source是指压缩后的不同类型的配置value。
抽象类PropertySource的常用子类如下所示: