PropertySources:持有一个或多个PropertySoucrce对象(如果对PropertySource不熟悉,建议看一下上一篇文章)
来看一下定义:
public interface PropertySources extends Iterable<PropertySource<?>>
该接口实现了Iterable接口,那么也就是该资源是可迭代,可foreach等功能;然后本身还提供了:
default Stream<PropertySource<?>> stream() {
return StreamSupport.stream(spliterator(), false);
}
boolean contains(String name);
@Nullable
PropertySource<?> get(String name);
通过这些接口信息我们可以看出,PropertySources主要提供对持有PropertySource提供操作扩展.
PropertySources仅有一个实现MutablePropertySources,因为这个类对理解spring环境比较重要,做一下详细说明,直接上源码:
public class MutablePropertySources implements PropertySources {
//资源hold,一个在写时copy的数组链表,可以并发访问
private final List<PropertySource<?>> propertySourceList = new CopyOnWriteArrayList<>();
/**
* Create a new {@link MutablePropertySources} object.
*/
public MutablePropertySources() {
}
/**
* Create a new {@code MutablePropertySources} from the given propertySources
* object, preserving the original order of contained {@code PropertySource} objects.
*/
public MutablePropertySources(PropertySources propertySources) {
this();
for (PropertySource<?> propertySource : propertySources) {
add