Re-introduce system-properties-mode to spring-context 3.1 XSD
See JIRA issue for complete details. Issue: SPR-8901
This commit is contained in:
@@ -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 <context:property-placeholder/>} 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}.
|
||||
*
|
||||
* <p>Local properties are added as a property source in any case. Precedence is based
|
||||
* on the value of the {@link #setLocalOverride localOverride} property.
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user