From 014f7f02428615b500acbe24f2044f2af3a62f73 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 10 Oct 2012 17:44:45 +0200 Subject: [PATCH] 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 --- .../context/support/AbstractApplicationContext.java | 8 +++----- .../context/support/EnvironmentIntegrationTests.java | 8 ++++---- .../org/springframework/web/portlet/FrameworkPortlet.java | 2 +- .../springframework/web/portlet/GenericPortletBean.java | 2 +- .../org/springframework/web/servlet/FrameworkServlet.java | 2 +- .../org/springframework/web/servlet/HttpServletBean.java | 2 +- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index 0f293027a34..a1402199254 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -398,7 +398,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader if (parent != null) { Environment parentEnvironment = parent.getEnvironment(); if (parentEnvironment instanceof ConfigurableEnvironment) { - getEnvironment().merge((ConfigurableEnvironment)parentEnvironment); + getEnvironment().merge((ConfigurableEnvironment) parentEnvironment); } } } @@ -578,12 +578,10 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader if (!beanFactory.containsLocalBean(ENVIRONMENT_BEAN_NAME)) { beanFactory.registerSingleton(ENVIRONMENT_BEAN_NAME, getEnvironment()); } - - if (!beanFactory.containsBean(SYSTEM_PROPERTIES_BEAN_NAME)) { + if (!beanFactory.containsLocalBean(SYSTEM_PROPERTIES_BEAN_NAME)) { beanFactory.registerSingleton(SYSTEM_PROPERTIES_BEAN_NAME, getEnvironment().getSystemProperties()); } - - if (!beanFactory.containsBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) { + if (!beanFactory.containsLocalBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) { beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, getEnvironment().getSystemEnvironment()); } } diff --git a/spring-context/src/test/java/org/springframework/context/support/EnvironmentIntegrationTests.java b/spring-context/src/test/java/org/springframework/context/support/EnvironmentIntegrationTests.java index dbe93cabaf6..9b11dfaf1b9 100644 --- a/spring-context/src/test/java/org/springframework/context/support/EnvironmentIntegrationTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/EnvironmentIntegrationTests.java @@ -17,19 +17,18 @@ package org.springframework.context.support; import org.junit.Test; + import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; -import static org.junit.Assert.*; - import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; /** - * Tests covering the integration of {@link Environment} into {@link ApplicationContext} - * hierarchies. + * Tests covering the integration of {@link Environment} into {@link ApplicationContext} hierarchies. * * @author Chris Beams */ @@ -51,4 +50,5 @@ public class EnvironmentIntegrationTests { sameInstance(child.getEnvironment()))); assertThat("expected child ctx env", env, sameInstance(child.getEnvironment())); } + } diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/FrameworkPortlet.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/FrameworkPortlet.java index e236a1d2268..ce8d4ad18b3 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/FrameworkPortlet.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/FrameworkPortlet.java @@ -345,7 +345,7 @@ public abstract class FrameworkPortlet extends GenericPortletBean pac.setId(ConfigurablePortletApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getPortletName()); } - pac.setEnvironment(this.getEnvironment()); + pac.setEnvironment(getEnvironment()); pac.setParent(parent); pac.setPortletContext(getPortletContext()); pac.setPortletConfig(getPortletConfig()); diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/GenericPortletBean.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/GenericPortletBean.java index 6351a90d83a..1006cd34054 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/GenericPortletBean.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/GenericPortletBean.java @@ -111,7 +111,7 @@ public abstract class GenericPortletBean extends GenericPortlet PropertyValues pvs = new PortletConfigPropertyValues(getPortletConfig(), this.requiredProperties); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new PortletContextResourceLoader(getPortletContext()); - bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.getEnvironment())); + bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment())); initBeanWrapper(bw); bw.setPropertyValues(pvs, true); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java index 570c5a1f0ec..f3cd6758a41 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java @@ -590,7 +590,7 @@ public abstract class FrameworkServlet extends HttpServletBean { ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass); - wac.setEnvironment(this.getEnvironment()); + wac.setEnvironment(getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java index ce0df647e09..e35e00ccfa9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java @@ -125,7 +125,7 @@ public abstract class HttpServletBean extends HttpServlet PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this); ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext()); - bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, this.getEnvironment())); + bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment())); initBeanWrapper(bw); bw.setPropertyValues(pvs, true); }