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 071d728b3b3..adce69cc6f1 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 @@ -35,14 +35,12 @@ import org.springframework.core.env.PropertySource; * be specified using {@link JndiLocatorDelegate#setJndiEnvironment(java.util.Properties)} * prior to construction of the {@code JndiPropertySource}. * - *
{@link org.springframework.web.context.support.StandardServletEnvironment - * StandardServletEnvironment} allows for declaratively including a - * {@code JndiPropertySource} through its support for a {@link - * org.springframework.web.context.support.StandardServletEnvironment#JNDI_PROPERTY_SOURCE_ENABLED - * JNDI_PROPERTY_SOURCE_ENABLED} context-param, but any customization of the underlying - * {@link JndiLocatorDelegate} will typically be done within an {@link - * org.springframework.context.ApplicationContextInitializer ApplicationContextInitializer} - * or {@link org.springframework.web.WebApplicationInitializer WebApplicationInitializer}. + *
Note that {@link org.springframework.web.context.support.StandardServletEnvironment
+ * StandardServletEnvironment} includes a {@code JndiPropertySource} by default, and any
+ * customization of the underlying {@link JndiLocatorDelegate} may be performed within an
+ * {@link org.springframework.context.ApplicationContextInitializer
+ * ApplicationContextInitializer} or {@link org.springframework.web.WebApplicationInitializer
+ * WebApplicationInitializer}.
*
* @author Chris Beams
* @author Juergen Hoeller
@@ -54,18 +52,6 @@ import org.springframework.core.env.PropertySource;
*/
public class JndiPropertySource extends PropertySource 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.
+ * Contributes {@code ServletConfig}, {@code ServletContext}, and JNDI-based
+ * {@link PropertySource} instances. See {@link #customizePropertySources} method
+ * documentation for details.
*
* @author Chris Beams
* @since 3.1
* @see StandardEnvironment
- * @see StandardPortletEnvironment
*/
public class StandardServletEnvironment extends StandardEnvironment {
@@ -55,11 +47,8 @@ public class StandardServletEnvironment extends StandardEnvironment {
/** Servlet config init parameters property source name: {@value} */
public static final String SERVLET_CONFIG_PROPERTY_SOURCE_NAME = "servletConfigInitParams";
- /**
- * Name of property used to determine if a {@link JndiPropertySource}
- * should be registered by default: {@value}
- */
- public static final String JNDI_PROPERTY_SOURCE_ENABLED_FLAG = "jndiPropertySourceEnabled";
+ /** JNDI property source name: {@value} */
+ public static final String JNDI_PROPERTY_SOURCE_NAME = "jndiProperties";
/**
@@ -68,21 +57,18 @@ public class StandardServletEnvironment extends StandardEnvironment {
* Properties present in {@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME} will
- * take precedence over those in {@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}.
+ * take precedence over those in {@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}, and
+ * properties found in either of the above take precedence over those found in
+ * {@value #JNDI_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.
- * 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.
* @see StandardEnvironment#customizePropertySources
* @see org.springframework.core.env.AbstractEnvironment#customizePropertySources
* @see ServletConfigPropertySource
@@ -95,10 +81,7 @@ public class StandardServletEnvironment extends StandardEnvironment {
protected void customizePropertySources(MutablePropertySources propertySources) {
propertySources.addLast(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME));
propertySources.addLast(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
+ propertySources.addLast(new JndiPropertySource(JNDI_PROPERTY_SOURCE_NAME));
super.customizePropertySources(propertySources);
-
- if (this.getProperty(JNDI_PROPERTY_SOURCE_ENABLED_FLAG, boolean.class, false)) {
- propertySources.addAfter(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, new JndiPropertySource());
- }
}
}
diff --git a/org.springframework.web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java b/org.springframework.web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java
index 068338a94e0..5c87bb7c057 100644
--- a/org.springframework.web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java
+++ b/org.springframework.web/src/test/java/org/springframework/web/context/support/StandardServletEnvironmentTests.java
@@ -19,14 +19,12 @@ package org.springframework.web.context.support;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.springframework.web.context.support.StandardServletEnvironment.JNDI_PROPERTY_SOURCE_ENABLED_FLAG;
import org.junit.Test;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
-import org.springframework.jndi.JndiPropertySource;
/**
* Unit tests for {@link StandardServletEnvironment}.
@@ -40,42 +38,13 @@ public class StandardServletEnvironmentTests {
public void propertySourceOrder() {
ConfigurableEnvironment env = new StandardServletEnvironment();
MutablePropertySources sources = env.getPropertySources();
- 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));
- }
-
- @Test
- public void propertySourceOrder_jndiPropertySourceEnabled() {
- System.setProperty(JNDI_PROPERTY_SOURCE_ENABLED_FLAG, "true");
- ConfigurableEnvironment env = new StandardServletEnvironment();
- MutablePropertySources sources = env.getPropertySources();
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(StandardServletEnvironment.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));
assertThat(sources.size(), is(5));
-
- System.clearProperty(JNDI_PROPERTY_SOURCE_ENABLED_FLAG);
}
- @Test
- public void propertySourceOrder_jndiPropertySourceEnabledIsFalse() {
- System.setProperty(JNDI_PROPERTY_SOURCE_ENABLED_FLAG, "false");
- ConfigurableEnvironment env = new StandardServletEnvironment();
- MutablePropertySources sources = env.getPropertySources();
-
- 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));
- assertThat(sources.size(), is(4));
-
- System.clearProperty(JNDI_PROPERTY_SOURCE_ENABLED_FLAG);
- }
}
*
*