From f893b62a9bd10a063a8e7b6842d003c3b625483f Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Fri, 20 May 2011 03:55:56 +0000 Subject: [PATCH] Rename {DefaultWeb=>StandardServlet}Environment Issue: SPR-8348 --- .../jndi/JndiPropertySource.java | 2 +- .../core/env/PropertySource.java | 2 +- .../core/env/StandardEnvironment.java | 44 ++++++++++--------- .../core/env/EnvironmentIntegrationTests.java | 38 ++++++++-------- .../context/DefaultPortletEnvironment.java | 10 ++--- .../web/servlet/HttpServletBean.java | 6 +-- ...tractRefreshableWebApplicationContext.java | 4 +- .../support/GenericWebApplicationContext.java | 4 +- ...tContextPropertyPlaceholderConfigurer.java | 2 +- ...t.java => StandardServletEnvironment.java} | 32 ++++++++------ .../support/StaticWebApplicationContext.java | 4 +- .../support/WebApplicationContextUtils.java | 12 ++--- .../web/filter/GenericFilterBean.java | 6 +-- ...a => StandardServletEnvironmentTests.java} | 26 ++++++----- 14 files changed, 102 insertions(+), 90 deletions(-) rename org.springframework.web/src/main/java/org/springframework/web/context/support/{DefaultWebEnvironment.java => StandardServletEnvironment.java} (80%) rename org.springframework.web/src/test/java/org/springframework/web/context/support/{DefaultWebEnvironmentTests.java => StandardServletEnvironmentTests.java} (72%) diff --git a/org.springframework.context/src/main/java/org/springframework/jndi/JndiPropertySource.java b/org.springframework.context/src/main/java/org/springframework/jndi/JndiPropertySource.java index b2f608e9d64..2655e9a83eb 100644 --- a/org.springframework.context/src/main/java/org/springframework/jndi/JndiPropertySource.java +++ b/org.springframework.context/src/main/java/org/springframework/jndi/JndiPropertySource.java @@ -32,7 +32,7 @@ import org.springframework.core.env.PropertySource; * @author Juergen Hoeller * @since 3.1 * @see Context#lookup(String) - * @see org.springframework.web.context.support.DefaultWebEnvironment + * @see org.springframework.web.context.support.StandardServletEnvironment */ public class JndiPropertySource extends PropertySource { diff --git a/org.springframework.core/src/main/java/org/springframework/core/env/PropertySource.java b/org.springframework.core/src/main/java/org/springframework/core/env/PropertySource.java index 3aba39a59f0..9a12ae49a5f 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/env/PropertySource.java +++ b/org.springframework.core/src/main/java/org/springframework/core/env/PropertySource.java @@ -205,7 +205,7 @@ public abstract class PropertySource { * during context refresh. * * @see org.springframework.context.support.AbstractApplicationContext#initPropertySources() - * @see org.springframework.web.context.support.DefaultWebEnvironment + * @see org.springframework.web.context.support.StandardServletEnvironment * @see org.springframework.web.context.support.ServletContextPropertySource */ public static class StubPropertySource extends PropertySource { diff --git a/org.springframework.core/src/main/java/org/springframework/core/env/StandardEnvironment.java b/org.springframework.core/src/main/java/org/springframework/core/env/StandardEnvironment.java index 69ca266f57f..f4bd038102a 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/env/StandardEnvironment.java +++ b/org.springframework.core/src/main/java/org/springframework/core/env/StandardEnvironment.java @@ -17,27 +17,28 @@ package org.springframework.core.env; /** - * Default implementation of the {@link Environment} interface. Used throughout all non-Web* - * ApplicationContext implementations. + * {@link Environment} implementation suitable for use in 'standard' (i.e. non-web) + * applications. * - *

In addition to the usual functions of a {@link ConfigurableEnvironment} such as property - * resolution and profile-related operations, this implementation configures two default property - * sources, to be searched in the following order: - *

    + *

    In addition to the usual functions of a {@link ConfigurableEnvironment} such as + * property resolution and profile-related operations, this implementation configures two + * default property sources, to be searched in the following order: + *

      *
    • {@linkplain AbstractEnvironment#getSystemProperties() system properties} *
    • {@linkplain AbstractEnvironment#getSystemEnvironment() system environment variables} - *
+ * * - * That is, if the key "xyz" is present both in the JVM system properties as well as in the - * set of environment variables for the current process, the value of key "xyz" from system properties - * will return from a call to {@code environment.getProperty("xyz")}. - * This ordering is chosen by default because system properties are per-JVM, while environment - * variables may be the same across many JVMs on a given system. Giving system properties - * precedence allows for overriding of environment variables on a per-JVM basis. + * That is, if the key "xyz" is present both in the JVM system properties as well as in + * the set of environment variables for the current process, the value of key "xyz" from + * system properties * will return from a call to {@code environment.getProperty("xyz")}. + * This ordering is chosen by default because system properties are per-JVM, while + * environment variables may be the same across many JVMs on a given system. Giving + * system properties precedence allows for overriding of environment variables on a + * per-JVM basis. * - *

These default property sources may be removed, reordered, or replaced; and additional - * property sources may be added using the {@link MutablePropertySources} instance available - * from {@link #getPropertySources()}. + *

These default property sources may be removed, reordered, or replaced; and + * additional property sources may be added using the {@link MutablePropertySources} + * instance available from {@link #getPropertySources()}. * *

Example: adding a new property source with highest search priority

*
@@ -62,16 +63,17 @@ package org.springframework.core.env;
  * 
* * When an {@link Environment} is being used by an ApplicationContext, it is important - * that any such PropertySource manipulations be performed before the context's {@link - * org.springframework.context.support.AbstractApplicationContext#refresh() refresh()} method is - * called. This ensures that all PropertySources are available during the container bootstrap process, - * including use by {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer + * that any such PropertySource manipulations be performed before the context's + * {@link org.springframework.context.support.AbstractApplicationContext#refresh() + * refresh()} method is called. This ensures that all PropertySources are available during + * the container bootstrap process, including use by + * {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer * property placeholder configurers}. * * @author Chris Beams * @since 3.1 * @see ConfigurableEnvironment - * @see org.springframework.web.context.support.DefaultWebEnvironment + * @see org.springframework.web.context.support.StandardServletEnvironment */ public class StandardEnvironment extends AbstractEnvironment { diff --git a/org.springframework.integration-tests/src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java b/org.springframework.integration-tests/src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java index c39ca126bca..c6e1e414f74 100644 --- a/org.springframework.integration-tests/src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java +++ b/org.springframework.integration-tests/src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java @@ -69,7 +69,7 @@ import org.springframework.util.FileCopyUtils; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AbstractRefreshableWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.context.support.DefaultWebEnvironment; +import org.springframework.web.context.support.StandardServletEnvironment; import org.springframework.web.context.support.GenericWebApplicationContext; import org.springframework.web.context.support.StaticWebApplicationContext; import org.springframework.web.context.support.XmlWebApplicationContext; @@ -346,7 +346,7 @@ public class EnvironmentIntegrationTests { GenericWebApplicationContext ctx = new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean()); - assertHasDefaultWebEnvironment(ctx); + assertHasStandardServletEnvironment(ctx); ctx.setEnvironment(prodEnv); ctx.refresh(); @@ -390,7 +390,7 @@ public class EnvironmentIntegrationTests { public void staticWebApplicationContext() { StaticWebApplicationContext ctx = new StaticWebApplicationContext(); - assertHasDefaultWebEnvironment(ctx); + assertHasStandardServletEnvironment(ctx); registerEnvironmentBeanDefinition(ctx); @@ -430,22 +430,22 @@ public class EnvironmentIntegrationTests { ctx.refresh(); ConfigurableEnvironment environment = ctx.getEnvironment(); - assertThat(environment, instanceOf(DefaultWebEnvironment.class)); + assertThat(environment, instanceOf(StandardServletEnvironment.class)); MutablePropertySources propertySources = environment.getPropertySources(); - assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true)); - assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true)); + assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true)); + assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true)); // ServletConfig gets precedence assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue")); - assertThat(propertySources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), - lessThan(propertySources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)))); + assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), + lessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)))); // but all params are available assertThat(environment.getProperty("pContext1"), is("pContext1Value")); assertThat(environment.getProperty("pConfig1"), is("pConfig1Value")); // Servlet* PropertySources have precedence over System* PropertySources - assertThat(propertySources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), + assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)))); // Replace system properties with a mock property source for convenience @@ -470,16 +470,16 @@ public class EnvironmentIntegrationTests { ctx.refresh(); ConfigurableEnvironment environment = ctx.getEnvironment(); - assertThat(environment, instanceOf(DefaultWebEnvironment.class)); + assertThat(environment, instanceOf(StandardServletEnvironment.class)); MutablePropertySources propertySources = environment.getPropertySources(); - assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true)); + assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true)); // ServletContext params are available assertThat(environment.getProperty("pCommon"), is("pCommonContextValue")); assertThat(environment.getProperty("pContext1"), is("pContext1Value")); // Servlet* PropertySources have precedence over System* PropertySources - assertThat(propertySources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), + assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)))); // Replace system properties with a mock property source for convenience @@ -509,20 +509,20 @@ public class EnvironmentIntegrationTests { ConfigurableEnvironment environment = ctx.getEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); - assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true)); - assertThat(propertySources.contains(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true)); + assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true)); + assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true)); // ServletConfig gets precedence assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue")); - assertThat(propertySources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), - lessThan(propertySources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)))); + assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), + lessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)))); // but all params are available assertThat(environment.getProperty("pContext1"), is("pContext1Value")); assertThat(environment.getProperty("pConfig1"), is("pConfig1Value")); // Servlet* PropertySources have precedence over System* PropertySources - assertThat(propertySources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), + assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)))); // Replace system properties with a mock property source for convenience @@ -632,11 +632,11 @@ public class EnvironmentIntegrationTests { assertThat(defaultEnv, instanceOf(StandardEnvironment.class)); } - private void assertHasDefaultWebEnvironment(WebApplicationContext ctx) { + private void assertHasStandardServletEnvironment(WebApplicationContext ctx) { // ensure a default web environment exists Environment defaultEnv = ctx.getEnvironment(); assertThat(defaultEnv, notNullValue()); - assertThat(defaultEnv, instanceOf(DefaultWebEnvironment.class)); + assertThat(defaultEnv, instanceOf(StandardServletEnvironment.class)); } private void assertHasDefaultPortletEnvironment(WebApplicationContext ctx) { diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/context/DefaultPortletEnvironment.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/context/DefaultPortletEnvironment.java index 5c6fff3cbfd..c4def113c00 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/context/DefaultPortletEnvironment.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/context/DefaultPortletEnvironment.java @@ -25,7 +25,7 @@ import org.springframework.core.env.Environment; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource.StubPropertySource; -import org.springframework.web.context.support.DefaultWebEnvironment; +import org.springframework.web.context.support.StandardServletEnvironment; /** * {@link Environment} implementation to be used by {@code Servlet}-based web @@ -39,7 +39,7 @@ import org.springframework.web.context.support.DefaultWebEnvironment; * @author Chris Beams * @since 3.1 * @see StandardEnvironment - * @see DefaultWebEnvironment + * @see StandardServletEnvironment */ public class DefaultPortletEnvironment extends StandardEnvironment { @@ -55,12 +55,12 @@ public class DefaultPortletEnvironment extends StandardEnvironment { *
    *
  • {@value #PORTLET_CONFIG_PROPERTY_SOURCE_NAME} *
  • {@value #PORTLET_CONTEXT_PROPERTY_SOURCE_NAME} - *
  • {@linkplain DefaultWebEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME "servletContextInitParams"} + *
  • {@linkplain StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME "servletContextInitParams"} *
*

Properties present in {@value #PORTLET_CONFIG_PROPERTY_SOURCE_NAME} will * take precedence over those in {@value #PORTLET_CONTEXT_PROPERTY_SOURCE_NAME}, * which takes precedence over those in - * {@linkplain DefaultWebEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME "servletContextInitParams"}. + * {@linkplain StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME "servletContextInitParams"}. *

Properties in any of the above will take precedence over system properties and environment * variables contributed by the {@link StandardEnvironment} superclass. *

The property sources are added as stubs for now, and will be @@ -77,7 +77,7 @@ public class DefaultPortletEnvironment extends StandardEnvironment { protected void customizePropertySources(MutablePropertySources propertySources) { propertySources.addLast(new StubPropertySource(PORTLET_CONFIG_PROPERTY_SOURCE_NAME)); propertySources.addLast(new StubPropertySource(PORTLET_CONTEXT_PROPERTY_SOURCE_NAME)); - propertySources.addLast(new StubPropertySource(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); + propertySources.addLast(new StubPropertySource(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)); super.customizePropertySources(propertySources); } } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HttpServletBean.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HttpServletBean.java index b2bb312ea25..127fbae308b 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HttpServletBean.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/HttpServletBean.java @@ -40,7 +40,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceEditor; import org.springframework.core.io.ResourceLoader; import org.springframework.util.StringUtils; -import org.springframework.web.context.support.DefaultWebEnvironment; +import org.springframework.web.context.support.StandardServletEnvironment; import org.springframework.web.context.support.ServletContextResourceLoader; /** @@ -87,7 +87,7 @@ public abstract class HttpServletBean extends HttpServlet implements Environment */ private final Set requiredProperties = new HashSet(); - private Environment environment = new DefaultWebEnvironment(); + private Environment environment = new StandardServletEnvironment(); /** @@ -182,7 +182,7 @@ public abstract class HttpServletBean extends HttpServlet implements Environment /** * {@inheritDoc} - *

Any environment set here overrides the {@link DefaultWebEnvironment} + *

Any environment set here overrides the {@link StandardServletEnvironment} * provided by default. */ public void setEnvironment(Environment environment) { diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java index 377cca40154..285b4040cc1 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java @@ -132,11 +132,11 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR } /** - * Create and return a new {@link DefaultWebEnvironment}. + * Create and return a new {@link StandardServletEnvironment}. */ @Override protected ConfigurableEnvironment createEnvironment() { - return new DefaultWebEnvironment(); + return new StandardServletEnvironment(); } diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java index 07afb7edf97..ea4e82d88fa 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java @@ -118,11 +118,11 @@ public class GenericWebApplicationContext extends GenericApplicationContext /** - * Create and return a new {@link DefaultWebEnvironment}. + * Create and return a new {@link StandardServletEnvironment}. */ @Override protected ConfigurableEnvironment createEnvironment() { - return new DefaultWebEnvironment(); + return new StandardServletEnvironment(); } /** diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/ServletContextPropertyPlaceholderConfigurer.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/ServletContextPropertyPlaceholderConfigurer.java index adfc6176261..31b17a07b5e 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/ServletContextPropertyPlaceholderConfigurer.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/ServletContextPropertyPlaceholderConfigurer.java @@ -59,7 +59,7 @@ import org.springframework.web.context.ServletContextAware; * @see javax.servlet.ServletContext#getInitParameter(String) * @see javax.servlet.ServletContext#getAttribute(String) * @deprecated in Spring 3.1 in favor of {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer} - * in conjunction with {@link org.springframework.web.context.support.DefaultWebEnvironment}. + * in conjunction with {@link org.springframework.web.context.support.StandardServletEnvironment}. */ @Deprecated public class ServletContextPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/DefaultWebEnvironment.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java similarity index 80% rename from org.springframework.web/src/main/java/org/springframework/web/context/support/DefaultWebEnvironment.java rename to org.springframework.web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java index c8a16d3f5d0..63c247ef2ee 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/DefaultWebEnvironment.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java @@ -32,20 +32,22 @@ import org.springframework.jndi.JndiPropertySource; * applications. All web-related (servlet-based) {@code ApplicationContext} classes * initialize an instance by default. * - *

Contributes {@code ServletConfig}- and {@code ServletContext}-based {@link PropertySource} - * instances. See the {@link #DefaultWebEnvironment()} constructor for details. + *

Contributes {@code ServletConfig}- and {@code ServletContext}-based + * {@link PropertySource} instances. See the {@link #customizePropertySources} method + * for details. * *

After initial bootstrapping, property sources will be searched for the presence of a - * "jndiPropertySourceEnabled" property; if found, a {@link JndiPropertySource} will be added - * to this environment's {@link PropertySources}, with precedence higher than system properties - * and environment variables, but lower than that of ServletContext and ServletConfig init params. + * "jndiPropertySourceEnabled" property; if found, a {@link JndiPropertySource} will be + * added to this environment's {@link PropertySources}, with precedence higher than system + * properties and environment variables, but lower than that of ServletContext and + * ServletConfig init params. * * @author Chris Beams * @since 3.1 * @see StandardEnvironment * @see DefaultPortletEnvironment */ -public class DefaultWebEnvironment extends StandardEnvironment { +public class StandardServletEnvironment extends StandardEnvironment { /** Servlet context init parameters property source name: {@value} */ public static final String SERVLET_CONTEXT_PROPERTY_SOURCE_NAME = "servletContextInitParams"; @@ -63,15 +65,17 @@ public class DefaultWebEnvironment extends StandardEnvironment { * *

Properties present in {@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME} will * take precedence over those in {@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}. - *

Properties in any of the above will take precedence over system properties and environment - * variables contributed by the {@link StandardEnvironment} superclass. - *

The {@code Servlet}-related property sources are added as stubs for now, and will be - * {@linkplain WebApplicationContextUtils#initServletPropertySources fully initialized} - * once the actual {@link ServletConfig} and {@link ServletContext} objects are available. + *

Properties in any of the above will take precedence over system properties and + * environment variables contributed by the {@link StandardEnvironment} superclass. + *

The {@code Servlet}-related property sources are added as stubs for now, and + * will be {@linkplain WebApplicationContextUtils#initServletPropertySources fully + * initialized} once the actual {@link ServletConfig} and {@link ServletContext} + * objects are available. *

If the {@link JndiPropertySource#JNDI_PROPERTY_SOURCE_ENABLED_FLAG "jndiPropertySourceEnabled"} - * property is present in any of the default property sources, a {@link JndiPropertySource} will - * be added as well, with precedence lower than servlet property sources, but higher than system - * properties and environment variables. + * property is present in any of the default property sources, a + * {@link JndiPropertySource} will be added as well, with precedence lower than + * servlet property sources, but higher than system properties and environment + * variables. * @see StandardEnvironment#customizePropertySources * @see ServletConfigPropertySource * @see ServletContextPropertySource diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java index dfa8e8c37ce..67cc216ade5 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java @@ -160,11 +160,11 @@ public class StaticWebApplicationContext extends StaticApplicationContext } /** - * Create and return a new {@link DefaultWebEnvironment}. + * Create and return a new {@link StandardServletEnvironment}. */ @Override protected ConfigurableEnvironment createEnvironment() { - return new DefaultWebEnvironment(); + return new StandardServletEnvironment(); } /** diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java index 3be23bf2852..eb607d1c318 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java @@ -247,13 +247,13 @@ public abstract class WebApplicationContextUtils { public static void initServletPropertySources( MutablePropertySources propertySources, ServletContext servletContext, ServletConfig servletConfig) { Assert.notNull(propertySources, "propertySources must not be null"); - if(servletContext != null && propertySources.contains(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)) { - propertySources.replace(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, - new ServletContextPropertySource(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, servletContext)); + if(servletContext != null && propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)) { + propertySources.replace(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, + new ServletContextPropertySource(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, servletContext)); } - if(servletConfig != null && propertySources.contains(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)) { - propertySources.replace(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME, - new ServletConfigPropertySource(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME, servletConfig)); + if(servletConfig != null && propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)) { + propertySources.replace(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME, + new ServletConfigPropertySource(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME, servletConfig)); } } diff --git a/org.springframework.web/src/main/java/org/springframework/web/filter/GenericFilterBean.java b/org.springframework.web/src/main/java/org/springframework/web/filter/GenericFilterBean.java index 431d918b165..51079e97ade 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/filter/GenericFilterBean.java +++ b/org.springframework.web/src/main/java/org/springframework/web/filter/GenericFilterBean.java @@ -44,7 +44,7 @@ import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.context.ServletContextAware; -import org.springframework.web.context.support.DefaultWebEnvironment; +import org.springframework.web.context.support.StandardServletEnvironment; import org.springframework.web.context.support.ServletContextResourceLoader; import org.springframework.web.util.NestedServletException; @@ -91,7 +91,7 @@ public abstract class GenericFilterBean implements private String beanName; - private Environment environment = new DefaultWebEnvironment(); + private Environment environment = new StandardServletEnvironment(); private ServletContext servletContext; @@ -109,7 +109,7 @@ public abstract class GenericFilterBean implements /** * {@inheritDoc} - *

Any environment set here overrides the {@link DefaultWebEnvironment} + *

Any environment set here overrides the {@link StandardServletEnvironment} * provided by default. */ public void setEnvironment(Environment environment) { diff --git a/org.springframework.web/src/test/java/org/springframework/web/context/support/DefaultWebEnvironmentTests.java b/org.springframework.web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java similarity index 72% rename from org.springframework.web/src/test/java/org/springframework/web/context/support/DefaultWebEnvironmentTests.java rename to org.springframework.web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java index ebe97fe9d1b..bf61846b832 100644 --- a/org.springframework.web/src/test/java/org/springframework/web/context/support/DefaultWebEnvironmentTests.java +++ b/org.springframework.web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java @@ -27,14 +27,20 @@ import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.jndi.JndiPropertySource; -public class DefaultWebEnvironmentTests { +/** + * Unit tests for {@link StandardServletEnvironment}. + * + * @author Chris Beams + * @since 3.1 + */ +public class StandardServletEnvironmentTests { @Test public void propertySourceOrder() { - ConfigurableEnvironment env = new DefaultWebEnvironment(); + ConfigurableEnvironment env = new StandardServletEnvironment(); MutablePropertySources sources = env.getPropertySources(); - assertThat(sources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0)); - assertThat(sources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1)); + assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0)); + assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1)); assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(2)); assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(3)); assertThat(sources.size(), is(4)); @@ -43,11 +49,11 @@ public class DefaultWebEnvironmentTests { @Test public void propertySourceOrder_jndiPropertySourceEnabled() { System.setProperty(JndiPropertySource.JNDI_PROPERTY_SOURCE_ENABLED_FLAG, "true"); - ConfigurableEnvironment env = new DefaultWebEnvironment(); + ConfigurableEnvironment env = new StandardServletEnvironment(); MutablePropertySources sources = env.getPropertySources(); - assertThat(sources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0)); - assertThat(sources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1)); + assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0)); + assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1)); assertThat(sources.precedenceOf(PropertySource.named(JndiPropertySource.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2)); assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3)); assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4)); @@ -59,11 +65,11 @@ public class DefaultWebEnvironmentTests { @Test public void propertySourceOrder_jndiPropertySourceEnabledIsFalse() { System.setProperty(JndiPropertySource.JNDI_PROPERTY_SOURCE_ENABLED_FLAG, "false"); - ConfigurableEnvironment env = new DefaultWebEnvironment(); + ConfigurableEnvironment env = new StandardServletEnvironment(); MutablePropertySources sources = env.getPropertySources(); - assertThat(sources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0)); - assertThat(sources.precedenceOf(PropertySource.named(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1)); + assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0)); + assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1)); //assertThat(sources.precedenceOf(PropertySource.named(JndiPropertySource.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2)); assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(2)); assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(3));