java为XmlWebApplicationContext设置spring字段环境的时机是什么?
我是spring framwork 4.2.0的新读者。发布源代码。当我在每一行代码运行时,我进入org。springframework。网状物上下文ContextLoaderListener
功能配置和刷新WebApplicationContext是:
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) {
if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
String idParam = sc.getInitParameter(CONTEXT_ID_PARAM);
if (idParam != null) {
wac.setId(idParam);
}
else {
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(sc.getContextPath()));
}
}
wac.setServletContext(sc);
String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM);
if (configLocationParam != null) {
wac.setConfigLocation(configLocationParam);
}
ConfigurableEnvironment env = wac.getEnvironment();
if (env instanceof ConfigurableWebEnvironment) {
((ConfigurableWebEnvironment) env).initPropertySources(sc, null);
}
customizeContext(sc, wac);
wac.refresh();
}
然而,行ConfigurableEnvironment=wac。getEnvironment()让我感到困惑。getEnvironment的函数是:
@Override
public ConfigurableEnvironment getEnvironment() {
if (this.environment == null) {
this.environment = createEnvironment();
}
return this.environment;
}
当我遵循此代码时,我发现环境=空,但我不知道spring何时以及如何设置环境
共 (0) 个答案