|
|
|
@ -41,10 +41,10 @@ import org.springframework.util.StringValueResolver; |
|
|
|
* Spring {@link Environment} and its set of {@link PropertySources}. |
|
|
|
* Spring {@link Environment} and its set of {@link PropertySources}. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>This class is designed as a general replacement for {@code PropertyPlaceholderConfigurer} |
|
|
|
* <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} |
|
|
|
* introduced in Spring 3.1. 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 |
|
|
|
* element in working against the spring-context-3.1 or higher XSD, whereas spring-context |
|
|
|
* <= 3.0 default to {@code PropertyPlaceholderConfigurer} to ensure backward compatibility. |
|
|
|
* versions <= 3.0 default to {@code PropertyPlaceholderConfigurer} to ensure backward |
|
|
|
* See the spring-context XSD documentation for complete details. |
|
|
|
* compatibility. See the spring-context XSD documentation for complete details. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>Any local properties (e.g. those added via {@link #setProperties}, {@link #setLocations} |
|
|
|
* <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 |
|
|
|
* et al.) are added as a {@code PropertySource}. Search precedence of local properties is |
|
|
|
@ -52,10 +52,11 @@ import org.springframework.util.StringValueResolver; |
|
|
|
* default {@code false} meaning that local properties are to be searched last, after all |
|
|
|
* default {@code false} meaning that local properties are to be searched last, after all |
|
|
|
* environment property sources. |
|
|
|
* environment property sources. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>See {@link org.springframework.core.env.ConfigurableEnvironment ConfigurableEnvironment} |
|
|
|
* <p>See {@link org.springframework.core.env.ConfigurableEnvironment} and related javadocs |
|
|
|
* and related javadocs for details on manipulating environment property sources. |
|
|
|
* for details on manipulating environment property sources. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Chris Beams |
|
|
|
* @author Chris Beams |
|
|
|
|
|
|
|
* @author Juergen Hoeller |
|
|
|
* @since 3.1 |
|
|
|
* @since 3.1 |
|
|
|
* @see org.springframework.core.env.ConfigurableEnvironment |
|
|
|
* @see org.springframework.core.env.ConfigurableEnvironment |
|
|
|
* @see org.springframework.beans.factory.config.PlaceholderConfigurerSupport |
|
|
|
* @see org.springframework.beans.factory.config.PlaceholderConfigurerSupport |
|
|
|
@ -88,8 +89,8 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Customize the set of {@link PropertySources} to be used by this configurer. |
|
|
|
* Customize the set of {@link PropertySources} to be used by this configurer. |
|
|
|
* Setting this property indicates that environment property sources and local |
|
|
|
* <p>Setting this property indicates that environment property sources and |
|
|
|
* properties should be ignored. |
|
|
|
* local properties should be ignored. |
|
|
|
* @see #postProcessBeanFactory |
|
|
|
* @see #postProcessBeanFactory |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setPropertySources(PropertySources propertySources) { |
|
|
|
public void setPropertySources(PropertySources propertySources) { |
|
|
|
@ -97,8 +98,8 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@inheritDoc} |
|
|
|
* {@code PropertySources} from the given {@link Environment} |
|
|
|
* <p>{@code PropertySources} from this environment will be searched when replacing ${...} placeholders. |
|
|
|
* will be searched when replacing ${...} placeholders. |
|
|
|
* @see #setPropertySources |
|
|
|
* @see #setPropertySources |
|
|
|
* @see #postProcessBeanFactory |
|
|
|
* @see #postProcessBeanFactory |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -109,8 +110,7 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@inheritDoc} |
|
|
|
* Processing occurs by replacing ${...} placeholders in bean definitions by resolving each |
|
|
|
* <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each |
|
|
|
|
|
|
|
* against this configurer's set of {@link PropertySources}, which includes: |
|
|
|
* against this configurer's set of {@link PropertySources}, which includes: |
|
|
|
* <ul> |
|
|
|
* <ul> |
|
|
|
* <li>all {@linkplain org.springframework.core.env.ConfigurableEnvironment#getPropertySources |
|
|
|
* <li>all {@linkplain org.springframework.core.env.ConfigurableEnvironment#getPropertySources |
|
|
|
@ -170,21 +170,23 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS |
|
|
|
propertyResolver.setValueSeparator(this.valueSeparator); |
|
|
|
propertyResolver.setValueSeparator(this.valueSeparator); |
|
|
|
|
|
|
|
|
|
|
|
StringValueResolver valueResolver = strVal -> { |
|
|
|
StringValueResolver valueResolver = strVal -> { |
|
|
|
String resolved = (ignoreUnresolvablePlaceholders ? |
|
|
|
String resolved = (this.ignoreUnresolvablePlaceholders ? |
|
|
|
propertyResolver.resolvePlaceholders(strVal) : |
|
|
|
propertyResolver.resolvePlaceholders(strVal) : |
|
|
|
propertyResolver.resolveRequiredPlaceholders(strVal)); |
|
|
|
propertyResolver.resolveRequiredPlaceholders(strVal)); |
|
|
|
if (trimValues) { |
|
|
|
if (this.trimValues) { |
|
|
|
resolved = resolved.trim(); |
|
|
|
resolved = resolved.trim(); |
|
|
|
} |
|
|
|
} |
|
|
|
return (resolved.equals(nullValue) ? null : resolved); |
|
|
|
return (resolved.equals(this.nullValue) ? null : resolved); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
doProcessProperties(beanFactoryToProcess, valueResolver); |
|
|
|
doProcessProperties(beanFactoryToProcess, valueResolver); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Implemented for compatibility with {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}. |
|
|
|
* Implemented for compatibility with |
|
|
|
* @deprecated in favor of {@link #processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)} |
|
|
|
* {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}. |
|
|
|
|
|
|
|
* @deprecated in favor of |
|
|
|
|
|
|
|
* {@link #processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)} |
|
|
|
* @throws UnsupportedOperationException in this implementation |
|
|
|
* @throws UnsupportedOperationException in this implementation |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -195,14 +197,14 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns the property sources that were actually applied during |
|
|
|
* Return the property sources that were actually applied during |
|
|
|
* {@link #postProcessBeanFactory(ConfigurableListableBeanFactory) post-processing}. |
|
|
|
* {@link #postProcessBeanFactory(ConfigurableListableBeanFactory) post-processing}. |
|
|
|
* @return the property sources that were applied |
|
|
|
* @return the property sources that were applied |
|
|
|
* @throws IllegalStateException if the property sources have not yet been applied |
|
|
|
* @throws IllegalStateException if the property sources have not yet been applied |
|
|
|
* @since 4.0 |
|
|
|
* @since 4.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public PropertySources getAppliedPropertySources() throws IllegalStateException { |
|
|
|
public PropertySources getAppliedPropertySources() throws IllegalStateException { |
|
|
|
Assert.state(this.appliedPropertySources != null, "PropertySources have not get been applied"); |
|
|
|
Assert.state(this.appliedPropertySources != null, "PropertySources have not yet been applied"); |
|
|
|
return this.appliedPropertySources; |
|
|
|
return this.appliedPropertySources; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|