diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/AbstractPropertyPlaceholderConfigurer.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java similarity index 98% rename from org.springframework.beans/src/main/java/org/springframework/beans/factory/config/AbstractPropertyPlaceholderConfigurer.java rename to org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java index 27dc5396f24..ddf060283c4 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/AbstractPropertyPlaceholderConfigurer.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PlaceholderConfigurerSupport.java @@ -85,7 +85,7 @@ import org.springframework.util.StringValueResolver; * @see PropertyPlaceholderConfigurer * @see org.springframework.context.support.PropertySourcesPlaceholderConfigurer */ -public abstract class AbstractPropertyPlaceholderConfigurer extends PropertyResourceConfigurer +public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfigurer implements BeanNameAware, BeanFactoryAware { /** Default placeholder prefix: {@value} */ @@ -97,6 +97,7 @@ public abstract class AbstractPropertyPlaceholderConfigurer extends PropertyReso /** Default value separator: {@value} */ public static final String DEFAULT_VALUE_SEPARATOR = ":"; + /** Defaults to {@value #DEFAULT_PLACEHOLDER_PREFIX} */ protected String placeholderPrefix = DEFAULT_PLACEHOLDER_PREFIX; @@ -189,8 +190,10 @@ public abstract class AbstractPropertyPlaceholderConfigurer extends PropertyReso this.beanFactory = beanFactory; } + protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver) { + BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver); String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames(); diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java index 95318a2a278..3974171cee5 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java @@ -20,15 +20,13 @@ import java.util.Properties; import java.util.Set; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.BeanNameAware; import org.springframework.core.Constants; import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; import org.springframework.util.StringValueResolver; /** - * {@link AbstractPropertyPlaceholderConfigurer} subclass that resolves ${...} placeholders + * {@link PlaceholderConfigurerSupport} subclass that resolves ${...} placeholders * against {@link #setLocation local} {@link #setProperties properties} and/or system properties * and environment variables. * @@ -39,18 +37,18 @@ import org.springframework.util.StringValueResolver; * *
{@link PropertyPlaceholderConfigurer} is still appropriate for use when: *
Prior to Spring 3.1, the {@code
Default implementation delegates to The default implementation delegates to Subclasses can override this for custom resolution strategies,
* including customized points for the system properties check.
@@ -209,6 +206,7 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
}
}
+
/**
* Visit each bean definition in the given bean factory and attempt to replace ${...} property
* placeholders with values from the given properties.
@@ -222,6 +220,25 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
this.doProcessProperties(beanFactoryToProcess, valueResolver);
}
+ /**
+ * Parse the given String value for placeholder resolution.
+ * @param strVal the String value to parse
+ * @param props the Properties to resolve placeholders against
+ * @param visitedPlaceholders the placeholders that have already been visited
+ * during the current resolution attempt (ignored in this version of the code)
+ * @deprecated as of Spring 3.0, in favor of using {@link #resolvePlaceholder}
+ * with {@link org.springframework.util.PropertyPlaceholderHelper}.
+ * Only retained for compatibility with Spring 2.5 extensions.
+ */
+ @Deprecated
+ protected String parseStringValue(String strVal, Properties props, Set> visitedPlaceholders) {
+ PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
+ placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders);
+ PlaceholderResolver resolver = new PropertyPlaceholderConfigurerResolver(props);
+ return helper.replacePlaceholders(strVal, resolver);
+ }
+
+
private class PlaceholderResolvingStringValueResolver implements StringValueResolver {
private final PropertyPlaceholderHelper helper;
@@ -240,23 +257,6 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
}
}
- /**
- * Parse the given String value for placeholder resolution.
- * @param strVal the String value to parse
- * @param props the Properties to resolve placeholders against
- * @param visitedPlaceholders the placeholders that have already been visited
- * during the current resolution attempt (ignored in this version of the code)
- * @deprecated as of Spring 3.0, in favor of using {@link #resolvePlaceholder}
- * with {@link org.springframework.util.PropertyPlaceholderHelper}.
- * Only retained for compatibility with Spring 2.5 extensions.
- */
- @Deprecated
- protected String parseStringValue(String strVal, Properties props, Set> visitedPlaceholders) {
- PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
- placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders);
- PlaceholderResolver resolver = new PropertyPlaceholderConfigurerResolver(props);
- return helper.replacePlaceholders(strVal, resolver);
- }
private class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver {
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 f3196453033..b0145b4cba1 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
@@ -17,11 +17,12 @@
package org.springframework.context.support;
import java.io.IOException;
+import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
-import org.springframework.beans.factory.config.AbstractPropertyPlaceholderConfigurer;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.config.PlaceholderConfigurerSupport;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.ConfigurablePropertyResolver;
import org.springframework.core.env.Environment;
@@ -33,17 +34,17 @@ import org.springframework.core.env.PropertySourcesPropertyResolver;
import org.springframework.util.StringValueResolver;
/**
- * Specialization of {@link AbstractPropertyPlaceholderConfigurer}
+ * Specialization of {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}
*
* Local properties are added as a property source in any case. Precedence is based
* on the value of the {@link #setLocalOverride localOverride} property.
*
* @author Chris Beams
* @since 3.1
- * @see AbstractPropertyPlaceholderConfigurer
+ * @see org.springframework.beans.factory.config.PlaceholderConfigurerSupport
* @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
*/
-public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceholderConfigurer
+public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerSupport
implements EnvironmentAware {
/**
@@ -58,21 +59,12 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
*/
public static final String ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME = "environmentProperties";
+
private MutablePropertySources propertySources;
private Environment environment;
- /**
- * {@inheritDoc}
- * {@code PropertySources} from this environment will be searched when replacing ${...} placeholders
- * @see #setPropertySources
- * @see #postProcessBeanFactory
- */
- public void setEnvironment(Environment environment) {
- this.environment = environment;
- }
-
/**
* Customize the set of {@link PropertySources} to be used by this configurer.
* Setting this property indicates that environment property sources and local
@@ -83,17 +75,28 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
this.propertySources = new MutablePropertySources(propertySources);
}
+ /**
+ * {@inheritDoc}
+ * {@code PropertySources} from this environment will be searched when replacing ${...} placeholders.
+ * @see #setPropertySources
+ * @see #postProcessBeanFactory
+ */
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
+
/**
* {@inheritDoc}
* Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
* against this configurer's set of {@link PropertySources}, which includes:
* If {@link #setPropertySources} is called, environment and local properties will be
* ignored. This method is designed to give the user fine-grained control over property
@@ -118,7 +121,8 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, this.mergeProperties());
if (this.localOverride) {
this.propertySources.addFirst(localPropertySource);
- } else {
+ }
+ else {
this.propertySources.addLast(localPropertySource);
}
}
@@ -150,20 +154,19 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
}
};
- this.doProcessProperties(beanFactoryToProcess, valueResolver);
+ doProcessProperties(beanFactoryToProcess, valueResolver);
}
/**
- * Implemented for compatibility with {@link AbstractPropertyPlaceholderConfigurer}.
+ * Implemented for compatibility with {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}.
* @deprecated in favor of {@link #processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)}
* @throws UnsupportedOperationException
*/
@Override
@Deprecated
- protected void processProperties(ConfigurableListableBeanFactory beanFactory, java.util.Properties props)
- throws BeansException {
+ protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) {
throw new UnsupportedOperationException(
- "call processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)");
+ "Call processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver) instead");
}
}
resolvePlaceholder
+ * resolvePlaceholder
* (placeholder, props) before/after the system properties check.
*
- *
*