renamed AbstractPropertyPlaceholderConfigurer to PlaceholderConfigurerSupport
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3985 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
c16e01cb14
commit
541f8595ab
|
|
@ -85,7 +85,7 @@ import org.springframework.util.StringValueResolver;
|
||||||
* @see PropertyPlaceholderConfigurer
|
* @see PropertyPlaceholderConfigurer
|
||||||
* @see org.springframework.context.support.PropertySourcesPlaceholderConfigurer
|
* @see org.springframework.context.support.PropertySourcesPlaceholderConfigurer
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractPropertyPlaceholderConfigurer extends PropertyResourceConfigurer
|
public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfigurer
|
||||||
implements BeanNameAware, BeanFactoryAware {
|
implements BeanNameAware, BeanFactoryAware {
|
||||||
|
|
||||||
/** Default placeholder prefix: {@value} */
|
/** Default placeholder prefix: {@value} */
|
||||||
|
|
@ -97,6 +97,7 @@ public abstract class AbstractPropertyPlaceholderConfigurer extends PropertyReso
|
||||||
/** Default value separator: {@value} */
|
/** Default value separator: {@value} */
|
||||||
public static final String DEFAULT_VALUE_SEPARATOR = ":";
|
public static final String DEFAULT_VALUE_SEPARATOR = ":";
|
||||||
|
|
||||||
|
|
||||||
/** Defaults to {@value #DEFAULT_PLACEHOLDER_PREFIX} */
|
/** Defaults to {@value #DEFAULT_PLACEHOLDER_PREFIX} */
|
||||||
protected String placeholderPrefix = DEFAULT_PLACEHOLDER_PREFIX;
|
protected String placeholderPrefix = DEFAULT_PLACEHOLDER_PREFIX;
|
||||||
|
|
||||||
|
|
@ -189,8 +190,10 @@ public abstract class AbstractPropertyPlaceholderConfigurer extends PropertyReso
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
|
protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
|
||||||
StringValueResolver valueResolver) {
|
StringValueResolver valueResolver) {
|
||||||
|
|
||||||
BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
|
BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);
|
||||||
|
|
||||||
String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
|
String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
|
||||||
|
|
@ -20,15 +20,13 @@ import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
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.core.Constants;
|
||||||
import org.springframework.util.PropertyPlaceholderHelper;
|
import org.springframework.util.PropertyPlaceholderHelper;
|
||||||
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
|
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
|
||||||
import org.springframework.util.StringValueResolver;
|
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
|
* against {@link #setLocation local} {@link #setProperties properties} and/or system properties
|
||||||
* and environment variables.
|
* and environment variables.
|
||||||
*
|
*
|
||||||
|
|
@ -50,7 +48,7 @@ import org.springframework.util.StringValueResolver;
|
||||||
*
|
*
|
||||||
* <p>Prior to Spring 3.1, the {@code <context:property-placeholder/>} namespace element
|
* <p>Prior to Spring 3.1, the {@code <context:property-placeholder/>} namespace element
|
||||||
* registered an instance of {@code PropertyPlaceholderConfigurer}. It will still do so if
|
* registered an instance of {@code PropertyPlaceholderConfigurer}. It will still do so if
|
||||||
* using the {@code spring-beans-3.0.xsd} definition of the namespace. That is, you can preserve
|
* using the {@code spring-context-3.0.xsd} definition of the namespace. That is, you can preserve
|
||||||
* registration of {@code PropertyPlaceholderConfigurer} through the namespace, even if using Spring 3.1;
|
* registration of {@code PropertyPlaceholderConfigurer} through the namespace, even if using Spring 3.1;
|
||||||
* simply do not update your {@code xsi:schemaLocation} and continue using the 3.0 XSD.
|
* simply do not update your {@code xsi:schemaLocation} and continue using the 3.0 XSD.
|
||||||
*
|
*
|
||||||
|
|
@ -58,12 +56,11 @@ import org.springframework.util.StringValueResolver;
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
* @since 02.10.2003
|
* @since 02.10.2003
|
||||||
* @see #setSystemPropertiesModeName
|
* @see #setSystemPropertiesModeName
|
||||||
* @see AbstractPropertyPlaceholderConfigurer
|
* @see PlaceholderConfigurerSupport
|
||||||
* @see PropertyOverrideConfigurer
|
* @see PropertyOverrideConfigurer
|
||||||
* @see org.springframework.context.support.PropertySourcesPlaceholderConfigurer
|
* @see org.springframework.context.support.PropertySourcesPlaceholderConfigurer
|
||||||
*/
|
*/
|
||||||
public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderConfigurer
|
public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport {
|
||||||
implements BeanNameAware, BeanFactoryAware {
|
|
||||||
|
|
||||||
/** Never check system properties. */
|
/** Never check system properties. */
|
||||||
public static final int SYSTEM_PROPERTIES_MODE_NEVER = 0;
|
public static final int SYSTEM_PROPERTIES_MODE_NEVER = 0;
|
||||||
|
|
@ -140,7 +137,7 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
|
||||||
/**
|
/**
|
||||||
* Resolve the given placeholder using the given properties, performing
|
* Resolve the given placeholder using the given properties, performing
|
||||||
* a system properties check according to the given mode.
|
* a system properties check according to the given mode.
|
||||||
* <p>Default implementation delegates to <code>resolvePlaceholder
|
* <p>The default implementation delegates to <code>resolvePlaceholder
|
||||||
* (placeholder, props)</code> before/after the system properties check.
|
* (placeholder, props)</code> before/after the system properties check.
|
||||||
* <p>Subclasses can override this for custom resolution strategies,
|
* <p>Subclasses can override this for custom resolution strategies,
|
||||||
* including customized points for the system properties check.
|
* 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
|
* Visit each bean definition in the given bean factory and attempt to replace ${...} property
|
||||||
* placeholders with values from the given properties.
|
* placeholders with values from the given properties.
|
||||||
|
|
@ -222,24 +220,6 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
|
||||||
this.doProcessProperties(beanFactoryToProcess, valueResolver);
|
this.doProcessProperties(beanFactoryToProcess, valueResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PlaceholderResolvingStringValueResolver implements StringValueResolver {
|
|
||||||
|
|
||||||
private final PropertyPlaceholderHelper helper;
|
|
||||||
|
|
||||||
private final PlaceholderResolver resolver;
|
|
||||||
|
|
||||||
public PlaceholderResolvingStringValueResolver(Properties props) {
|
|
||||||
this.helper = new PropertyPlaceholderHelper(
|
|
||||||
placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders);
|
|
||||||
this.resolver = new PropertyPlaceholderConfigurerResolver(props);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String resolveStringValue(String strVal) throws BeansException {
|
|
||||||
String value = this.helper.replacePlaceholders(strVal, this.resolver);
|
|
||||||
return (value.equals(nullValue) ? null : value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the given String value for placeholder resolution.
|
* Parse the given String value for placeholder resolution.
|
||||||
* @param strVal the String value to parse
|
* @param strVal the String value to parse
|
||||||
|
|
@ -258,6 +238,26 @@ public class PropertyPlaceholderConfigurer extends AbstractPropertyPlaceholderCo
|
||||||
return helper.replacePlaceholders(strVal, resolver);
|
return helper.replacePlaceholders(strVal, resolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private class PlaceholderResolvingStringValueResolver implements StringValueResolver {
|
||||||
|
|
||||||
|
private final PropertyPlaceholderHelper helper;
|
||||||
|
|
||||||
|
private final PlaceholderResolver resolver;
|
||||||
|
|
||||||
|
public PlaceholderResolvingStringValueResolver(Properties props) {
|
||||||
|
this.helper = new PropertyPlaceholderHelper(
|
||||||
|
placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders);
|
||||||
|
this.resolver = new PropertyPlaceholderConfigurerResolver(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String resolveStringValue(String strVal) throws BeansException {
|
||||||
|
String value = this.helper.replacePlaceholders(strVal, this.resolver);
|
||||||
|
return (value.equals(nullValue) ? null : value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver {
|
private class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver {
|
||||||
|
|
||||||
private final Properties props;
|
private final Properties props;
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,12 @@
|
||||||
package org.springframework.context.support;
|
package org.springframework.context.support;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.BeanInitializationException;
|
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.ConfigurableListableBeanFactory;
|
||||||
|
import org.springframework.beans.factory.config.PlaceholderConfigurerSupport;
|
||||||
import org.springframework.context.EnvironmentAware;
|
import org.springframework.context.EnvironmentAware;
|
||||||
import org.springframework.core.env.ConfigurablePropertyResolver;
|
import org.springframework.core.env.ConfigurablePropertyResolver;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
@ -33,17 +34,17 @@ import org.springframework.core.env.PropertySourcesPropertyResolver;
|
||||||
import org.springframework.util.StringValueResolver;
|
import org.springframework.util.StringValueResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specialization of {@link AbstractPropertyPlaceholderConfigurer}
|
* Specialization of {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}
|
||||||
*
|
*
|
||||||
* <p>Local properties are added as a property source in any case. Precedence is based
|
* <p>Local properties are added as a property source in any case. Precedence is based
|
||||||
* on the value of the {@link #setLocalOverride localOverride} property.
|
* on the value of the {@link #setLocalOverride localOverride} property.
|
||||||
*
|
*
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
* @see AbstractPropertyPlaceholderConfigurer
|
* @see org.springframework.beans.factory.config.PlaceholderConfigurerSupport
|
||||||
* @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
|
* @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
|
||||||
*/
|
*/
|
||||||
public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceholderConfigurer
|
public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerSupport
|
||||||
implements EnvironmentAware {
|
implements EnvironmentAware {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,21 +59,12 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
|
||||||
*/
|
*/
|
||||||
public static final String ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME = "environmentProperties";
|
public static final String ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME = "environmentProperties";
|
||||||
|
|
||||||
|
|
||||||
private MutablePropertySources propertySources;
|
private MutablePropertySources propertySources;
|
||||||
|
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* <p>{@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.
|
* Customize the set of {@link PropertySources} to be used by this configurer.
|
||||||
* Setting this property indicates that environment property sources and local
|
* Setting this property indicates that environment property sources and local
|
||||||
|
|
@ -83,6 +75,17 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
|
||||||
this.propertySources = new MutablePropertySources(propertySources);
|
this.propertySources = new MutablePropertySources(propertySources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* <p>{@code PropertySources} from this environment will be searched when replacing ${...} placeholders.
|
||||||
|
* @see #setPropertySources
|
||||||
|
* @see #postProcessBeanFactory
|
||||||
|
*/
|
||||||
|
public void setEnvironment(Environment environment) {
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
|
* <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
|
||||||
|
|
@ -118,7 +121,8 @@ public class PropertySourcesPlaceholderConfigurer extends AbstractPropertyPlaceh
|
||||||
new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, this.mergeProperties());
|
new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, this.mergeProperties());
|
||||||
if (this.localOverride) {
|
if (this.localOverride) {
|
||||||
this.propertySources.addFirst(localPropertySource);
|
this.propertySources.addFirst(localPropertySource);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.propertySources.addLast(localPropertySource);
|
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)}
|
* @deprecated in favor of {@link #processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)}
|
||||||
* @throws UnsupportedOperationException
|
* @throws UnsupportedOperationException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected void processProperties(ConfigurableListableBeanFactory beanFactory, java.util.Properties props)
|
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) {
|
||||||
throws BeansException {
|
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
"call processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)");
|
"Call processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver) instead");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue