Rename {DefaultWeb=>StandardServlet}Environment

Issue: SPR-8348
This commit is contained in:
Chris Beams 2011-05-20 03:55:56 +00:00
parent c06752ef72
commit f893b62a9b
14 changed files with 102 additions and 90 deletions

View File

@ -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<Context> {

View File

@ -205,7 +205,7 @@ public abstract class PropertySource<T> {
* 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<Object> {

View File

@ -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.
*
* <p>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:
* <ol>
* <p>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:
* <ul>
* <li>{@linkplain AbstractEnvironment#getSystemProperties() system properties}
* <li>{@linkplain AbstractEnvironment#getSystemEnvironment() system environment variables}
* </ol>
* </ul>
*
* 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.
*
* <p>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()}.
* <p>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()}.
*
* <h4>Example: adding a new property source with highest search priority</h4>
* <pre class="code">
@ -62,16 +63,17 @@ package org.springframework.core.env;
* </pre>
*
* When an {@link Environment} is being used by an ApplicationContext, it is important
* that any such PropertySource manipulations be performed <em>before</em> 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 <em>before</em> 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 {

View File

@ -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) {

View File

@ -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 {
* <ul>
* <li>{@value #PORTLET_CONFIG_PROPERTY_SOURCE_NAME}
* <li>{@value #PORTLET_CONTEXT_PROPERTY_SOURCE_NAME}
* <li>{@linkplain DefaultWebEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME "servletContextInitParams"}
* <li>{@linkplain StandardServletEnvironment#SERVLET_CONTEXT_PROPERTY_SOURCE_NAME "servletContextInitParams"}
* </ul>
* <p>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"}.
* <p>Properties in any of the above will take precedence over system properties and environment
* variables contributed by the {@link StandardEnvironment} superclass.
* <p>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);
}
}

View File

@ -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<String> requiredProperties = new HashSet<String>();
private Environment environment = new DefaultWebEnvironment();
private Environment environment = new StandardServletEnvironment();
/**
@ -182,7 +182,7 @@ public abstract class HttpServletBean extends HttpServlet implements Environment
/**
* {@inheritDoc}
* <p>Any environment set here overrides the {@link DefaultWebEnvironment}
* <p>Any environment set here overrides the {@link StandardServletEnvironment}
* provided by default.
*/
public void setEnvironment(Environment environment) {

View File

@ -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();
}

View File

@ -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();
}
/**

View File

@ -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

View File

@ -32,20 +32,22 @@ import org.springframework.jndi.JndiPropertySource;
* applications. All web-related (servlet-based) {@code ApplicationContext} classes
* initialize an instance by default.
*
* <p>Contributes {@code ServletConfig}- and {@code ServletContext}-based {@link PropertySource}
* instances. See the {@link #DefaultWebEnvironment()} constructor for details.
* <p>Contributes {@code ServletConfig}- and {@code ServletContext}-based
* {@link PropertySource} instances. See the {@link #customizePropertySources} method
* for details.
*
* <p>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 {
* </ul>
* <p>Properties present in {@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME} will
* take precedence over those in {@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}.
* <p>Properties in any of the above will take precedence over system properties and environment
* variables contributed by the {@link StandardEnvironment} superclass.
* <p>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.
* <p>Properties in any of the above will take precedence over system properties and
* environment variables contributed by the {@link StandardEnvironment} superclass.
* <p>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.
* <p>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

View File

@ -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();
}
/**

View File

@ -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));
}
}

View File

@ -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}
* <p>Any environment set here overrides the {@link DefaultWebEnvironment}
* <p>Any environment set here overrides the {@link StandardServletEnvironment}
* provided by default.
*/
public void setEnvironment(Environment environment) {

View File

@ -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));