【Spring源码这样读】-细扒ApplicationContext之setConfigLocations(configLocations)

511 阅读1分钟

细扒之继续讲容器初始化流程,上篇讲了super(parent),本章初始化的下一步setConfigLocations(configLocations);大佬请略过

setConfigLocations(configLocations)对应源码

public void setConfigLocations(@Nullable String... locations) {
	if (locations != null) {
		Assert.noNullElements(locations, "Config locations must not be null");
		this.configLocations = new String[locations.length];
		for (int i = 0; i < locations.length; i++) {
			this.configLocations[i] = resolvePath(locations[i]).trim();
		}
	}
	else {
		this.configLocations = null;
	}
}

protected String resolvePath(String path) {
	return getEnvironment().resolveRequiredPlaceholders(path);
}

源码的注释其实写得比较明了,一句话概括了:设置此应用程序上下文的配置位置,如果未设置,则实现可酌情使用默认值。