Changes along with 3.1.3 backport
Aside from minor polishing, this change sets the "systemProperties" and "systemEnvironment" beans at each factory level as well. Issue: SPR-9756 Issue: SPR-9764
This commit is contained in:
parent
9eeb6f15e5
commit
014f7f0242
|
@ -578,12 +578,10 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
if (!beanFactory.containsLocalBean(ENVIRONMENT_BEAN_NAME)) {
|
if (!beanFactory.containsLocalBean(ENVIRONMENT_BEAN_NAME)) {
|
||||||
beanFactory.registerSingleton(ENVIRONMENT_BEAN_NAME, getEnvironment());
|
beanFactory.registerSingleton(ENVIRONMENT_BEAN_NAME, getEnvironment());
|
||||||
}
|
}
|
||||||
|
if (!beanFactory.containsLocalBean(SYSTEM_PROPERTIES_BEAN_NAME)) {
|
||||||
if (!beanFactory.containsBean(SYSTEM_PROPERTIES_BEAN_NAME)) {
|
|
||||||
beanFactory.registerSingleton(SYSTEM_PROPERTIES_BEAN_NAME, getEnvironment().getSystemProperties());
|
beanFactory.registerSingleton(SYSTEM_PROPERTIES_BEAN_NAME, getEnvironment().getSystemProperties());
|
||||||
}
|
}
|
||||||
|
if (!beanFactory.containsLocalBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) {
|
||||||
if (!beanFactory.containsBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) {
|
|
||||||
beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, getEnvironment().getSystemEnvironment());
|
beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, getEnvironment().getSystemEnvironment());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,19 +17,18 @@
|
||||||
package org.springframework.context.support;
|
package org.springframework.context.support;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests covering the integration of {@link Environment} into {@link ApplicationContext}
|
* Tests covering the integration of {@link Environment} into {@link ApplicationContext} hierarchies.
|
||||||
* hierarchies.
|
|
||||||
*
|
*
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
|
@ -51,4 +50,5 @@ public class EnvironmentIntegrationTests {
|
||||||
sameInstance(child.getEnvironment())));
|
sameInstance(child.getEnvironment())));
|
||||||
assertThat("expected child ctx env", env, sameInstance(child.getEnvironment()));
|
assertThat("expected child ctx env", env, sameInstance(child.getEnvironment()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,7 +345,7 @@ public abstract class FrameworkPortlet extends GenericPortletBean
|
||||||
pac.setId(ConfigurablePortletApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getPortletName());
|
pac.setId(ConfigurablePortletApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getPortletName());
|
||||||
}
|
}
|
||||||
|
|
||||||
pac.setEnvironment(this.getEnvironment());
|
pac.setEnvironment(getEnvironment());
|
||||||
pac.setParent(parent);
|
pac.setParent(parent);
|
||||||
pac.setPortletContext(getPortletContext());
|
pac.setPortletContext(getPortletContext());
|
||||||
pac.setPortletConfig(getPortletConfig());
|
pac.setPortletConfig(getPortletConfig());
|
||||||
|
|
|
@ -111,7 +111,7 @@ public abstract class GenericPortletBean extends GenericPortlet
|
||||||
PropertyValues pvs = new PortletConfigPropertyValues(getPortletConfig(), this.requiredProperties);
|
PropertyValues pvs = new PortletConfigPropertyValues(getPortletConfig(), this.requiredProperties);
|
||||||
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
|
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
|
||||||
ResourceLoader resourceLoader = new PortletContextResourceLoader(getPortletContext());
|
ResourceLoader resourceLoader = new PortletContextResourceLoader(getPortletContext());
|
||||||
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.getEnvironment()));
|
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
|
||||||
initBeanWrapper(bw);
|
initBeanWrapper(bw);
|
||||||
bw.setPropertyValues(pvs, true);
|
bw.setPropertyValues(pvs, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -590,7 +590,7 @@ public abstract class FrameworkServlet extends HttpServletBean {
|
||||||
ConfigurableWebApplicationContext wac =
|
ConfigurableWebApplicationContext wac =
|
||||||
(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
|
(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
|
||||||
|
|
||||||
wac.setEnvironment(this.getEnvironment());
|
wac.setEnvironment(getEnvironment());
|
||||||
wac.setParent(parent);
|
wac.setParent(parent);
|
||||||
wac.setConfigLocation(getContextConfigLocation());
|
wac.setConfigLocation(getContextConfigLocation());
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ public abstract class HttpServletBean extends HttpServlet
|
||||||
PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);
|
PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);
|
||||||
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
|
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
|
||||||
ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
|
ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
|
||||||
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.getEnvironment()));
|
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
|
||||||
initBeanWrapper(bw);
|
initBeanWrapper(bw);
|
||||||
bw.setPropertyValues(pvs, true);
|
bw.setPropertyValues(pvs, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue