Spring EnumerablePropertySource

  • Author: HuiFer

  • 源码阅读仓库: SourceHot-spring

  • 全路径: org.springframework.core.env.EnumerablePropertySource

  • 在这个类中定义了一个抽象方法getPropertyNames 用来获取所有的 property 的名称

1
	public abstract String[] getPropertyNames();
  • 整体代码如下
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public abstract class EnumerablePropertySource<T> extends PropertySource<T> {

	public EnumerablePropertySource(String name, T source) {
		super(name, source);
	}

	protected EnumerablePropertySource(String name) {
		super(name);
	}


	/**
	 * Return whether this {@code PropertySource} contains a property with the given name.
	 * <p>This implementation checks for the presence of the given name within the
	 * {@link #getPropertyNames()} array.
	 *
	 * 在属性列表中是否存在 properties
	 * @param name the name of the property to find
	 */
	@Override
	public boolean containsProperty(String name) {
		return ObjectUtils.containsElement(getPropertyNames(), name);
	}

	/**
	 * Return the names of all properties contained by the
	 * 获取所有的 properties 名称
	 * {@linkplain #getSource() source} object (never {@code null}).
	 */
	public abstract String[] getPropertyNames();

}