diff --git a/org.springframework.context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java b/org.springframework.context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java
index 256f61e65f..60d55605b3 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.util.StringUtils;
/**
- * Parser for the <context:property-placeholder/> element.
+ * Parser for the {@code } element.
*
* @author Juergen Hoeller
* @author Dave Syer
@@ -33,13 +33,22 @@ import org.springframework.util.StringUtils;
*/
class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBeanDefinitionParser {
+ private static final String SYSTEM_PROPERTIES_MODE_ATTRIB = "system-properties-mode";
+ private static final String SYSTEM_PROPERTIES_MODE_DEFAULT = "ENVIRONMENT";
+
@Override
protected Class> getBeanClass(Element element) {
- if (element.hasAttribute("system-properties-mode")) {
- return PropertyPlaceholderConfigurer.class;
+ // As of Spring 3.1, the default value of system-properties-mode has changed from
+ // 'FALLBACK' to 'ENVIRONMENT'. This latter value indicates that resolution of
+ // placeholders against system properties is a function of the Environment and
+ // its current set of PropertySources
+ if (element.getAttribute(SYSTEM_PROPERTIES_MODE_ATTRIB).equals(SYSTEM_PROPERTIES_MODE_DEFAULT)) {
+ return PropertySourcesPlaceholderConfigurer.class;
}
- return PropertySourcesPlaceholderConfigurer.class;
+ // the user has explicitly specified a value for system-properties-mode. Revert
+ // to PropertyPlaceholderConfigurer to ensure backward compatibility.
+ return PropertyPlaceholderConfigurer.class;
}
@Override
@@ -49,8 +58,9 @@ class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBea
builder.addPropertyValue("ignoreUnresolvablePlaceholders",
Boolean.valueOf(element.getAttribute("ignore-unresolvable")));
- String systemPropertiesModeName = element.getAttribute("system-properties-mode");
- if (StringUtils.hasLength(systemPropertiesModeName)) {
+ String systemPropertiesModeName = element.getAttribute(SYSTEM_PROPERTIES_MODE_ATTRIB);
+ if (StringUtils.hasLength(systemPropertiesModeName) &&
+ !systemPropertiesModeName.equals(SYSTEM_PROPERTIES_MODE_DEFAULT)) {
builder.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_"+systemPropertiesModeName);
}
}
diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java b/org.springframework.context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java
index b0145b4cba..aa8d9e7992 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java
@@ -34,13 +34,30 @@ import org.springframework.core.env.PropertySourcesPropertyResolver;
import org.springframework.util.StringValueResolver;
/**
- * Specialization of {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}
+ * Specialization of {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport
+ * PlaceholderConfigurerSupport} that resolves ${...} placeholders within bean definition
+ * property values and {@code @Value} annotations against the current Spring {@link
+ * Environment} and its set of {@link PropertySources}.
*
- *
Local properties are added as a property source in any case. Precedence is based
- * on the value of the {@link #setLocalOverride localOverride} property.
+ *
This class is designed as a general replacement for {@code
+ * PropertyPlaceholderConfigurer} in Spring 3.1 applications. It is used by default to
+ * support the {@code property-placeholder} element in working against the
+ * spring-context-3.1 XSD, whereas spring-context versions <= 3.0 default to
+ * {@code PropertyPlaceholderConfigurer} to ensure backward compatibility. See
+ * spring-context XSD documentation for complete details.
+ *
+ *
Any local properties (e.g. those added via {@link #setProperties},
+ * {@link #setLocations} et al.) are added as a {@code PropertySource}. Search precedence
+ * of local properties is based on the value of the {@link #setLocalOverride localOverride}
+ * property, which is by default {@code false} meaning that local properties are to be
+ * searched last, after all environment property sources.
+ *
+ *
See {@link org.springframework.core.env.ConfigurableEnvironment ConfigurableEnvironment}
+ * and related Javadoc for details on manipulating environment property sources.
*
* @author Chris Beams
* @since 3.1
+ * @see org.springframework.core.env.ConfigurableEnvironment
* @see org.springframework.beans.factory.config.PlaceholderConfigurerSupport
* @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
*/
diff --git a/org.springframework.context/src/main/resources/org/springframework/context/config/spring-context-3.1.xsd b/org.springframework.context/src/main/resources/org/springframework/context/config/spring-context-3.1.xsd
index c672df54f7..b2132e4e1c 100644
--- a/org.springframework.context/src/main/resources/org/springframework/context/config/spring-context-3.1.xsd
+++ b/org.springframework.context/src/main/resources/org/springframework/context/config/spring-context-3.1.xsd
@@ -89,10 +89,20 @@
@@ -103,7 +113,39 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -360,10 +402,6 @@
Signals the current application context to apply dependency injection
to non-managed classes that are instantiated outside of the Spring bean
factory (typically classes annotated with the @Configurable annotation).
-
- See Javadoc for org.springframework.context.annotation.EnableSpringConfigured in the
- spring-aspects module for information on code-based alternatives to bootstrapping
- this functionality.
]]>
diff --git a/org.springframework.context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-system.xml b/org.springframework.context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-system.xml
index 9c475282fc..d5268c52bc 100644
--- a/org.springframework.context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-system.xml
+++ b/org.springframework.context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-system.xml
@@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">