spring-全量自定义-PropertySources

本文介绍了Spring中的PropertySources,它作为一个可迭代接口,允许对PropertySource进行操作和扩展。重点解析了其唯一实现类MutablePropertySources,通过源码分析帮助理解Spring环境的配置处理。
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值