Top Description Inners Fields Constructors Methods
org.springframework.beans.factory.config

public Class PropertyPlaceholderConfigurer

extends PlaceholderConfigurerSupport
Class Inheritance
Known Direct Subclasses
org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer
Annotations
@Deprecated
Imports
java.util.Map, .Properties, org.springframework.beans.BeansException, org.springframework.core.SpringProperties, org.springframework.core.env.AbstractEnvironment, org.springframework.lang.Nullable, org.springframework.util.Assert, .PropertyPlaceholderHelper, .PropertyPlaceholderHelper.PlaceholderResolver, .StringValueResolver

Deprecated

as of 5.2; use org.springframework.context.support.PropertySourcesPlaceholderConfigurer instead which is more flexible through taking advantage of the org.springframework.core.env.Environment and org.springframework.core.env.PropertySource mechanisms.

PlaceholderConfigurerSupport subclass that resolves ${...} placeholders against local properties and/or system properties and environment variables.

PropertyPlaceholderConfigurer is still appropriate for use when:

Authors
Juergen Hoeller, Chris Beams, Sam Brannen
Since
02.10.2003
See Also
setSystemPropertiesModeName, PlaceholderConfigurerSupport, PropertyOverrideConfigurer

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private static final Map<String, Integer>
constants

Map of constant names to constant values for the system properties mode constants defined in this class.

private boolean
public static final int
SYSTEM_PROPERTIES_MODE_FALLBACK

Check system properties if not resolvable in the specified properties.

public static final int
SYSTEM_PROPERTIES_MODE_NEVER

Never check system properties.

public static final int
SYSTEM_PROPERTIES_MODE_OVERRIDE

Check system properties first, before trying the specified properties.

private int
Inherited from org.springframework.beans.factory.config.PlaceholderConfigurerSupport:
DEFAULT_PLACEHOLDER_PREFIXDEFAULT_PLACEHOLDER_SUFFIXDEFAULT_VALUE_SEPARATORignoreUnresolvablePlaceholdersnullValueplaceholderPrefixplaceholderSuffixtrimValuesvalueSeparator

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
processProperties(ConfigurableListableBeanFactory
the BeanFactory used by the application context
beanFactoryToProcess
,
Properties
the Properties to apply
props
)

Implements abstract org.springframework.beans.factory.config.PropertyResourceConfigurer.processProperties.

Visit each bean definition in the given bean factory and attempt to replace ${...} property placeholders with values from the given properties.

protected String

Returns:

the resolved value, of null if none
resolvePlaceholder
(String
the placeholder to resolve
placeholder
,
Properties
the merged properties of this configurer
props
,
int
the system properties mode, according to the constants in this class
systemPropertiesMode
)

Resolve the given placeholder using the given properties, performing a system properties check according to the given mode.

protected String

Returns:

the resolved value, of null if none
resolvePlaceholder
(String
the placeholder to resolve
placeholder
,
Properties
the merged properties of this configurer
props
)

Resolve the given placeholder using the given properties.

protected String

Returns:

the system property value, or null if not found
resolveSystemProperty
(String
the placeholder to resolve as system property key
key
)

Resolve the given key as JVM system property, and optionally also as system environment variable if no matching system property has been found.

public void
setSearchSystemEnvironment(boolean searchSystemEnvironment)

Set whether to search for a matching system environment variable if no matching system property has been found.

public void
setSystemPropertiesMode(int systemPropertiesMode)

Set how to check system properties: as fallback, as override, or never.

public void
setSystemPropertiesModeName(String
name of the constant
constantName
)

Set the system property mode by the name of the corresponding constant, e.g. "SYSTEM_PROPERTIES_MODE_OVERRIDE".

Inherited from org.springframework.beans.factory.config.PlaceholderConfigurerSupport:
doProcessPropertiessetBeanFactorysetBeanNamesetIgnoreUnresolvablePlaceholderssetNullValuesetPlaceholderPrefixsetPlaceholderSuffixsetTrimValuessetValueSeparator

Field Detail

constantsback to summary
private static final Map<String, Integer> constants

Map of constant names to constant values for the system properties mode constants defined in this class.

searchSystemEnvironmentback to summary
private boolean searchSystemEnvironment
SYSTEM_PROPERTIES_MODE_FALLBACKback to summary
public static final int SYSTEM_PROPERTIES_MODE_FALLBACK

Check system properties if not resolvable in the specified properties. This is the default.

SYSTEM_PROPERTIES_MODE_NEVERback to summary
public static final int SYSTEM_PROPERTIES_MODE_NEVER

Never check system properties.

SYSTEM_PROPERTIES_MODE_OVERRIDEback to summary
public static final int SYSTEM_PROPERTIES_MODE_OVERRIDE

Check system properties first, before trying the specified properties. This allows system properties to override any other property source.

systemPropertiesModeback to summary
private int systemPropertiesMode

Constructor Detail

PropertyPlaceholderConfigurerback to summary
public PropertyPlaceholderConfigurer()

Method Detail

processPropertiesback to summary
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException

Implements abstract org.springframework.beans.factory.config.PropertyResourceConfigurer.processProperties.

Visit each bean definition in the given bean factory and attempt to replace ${...} property placeholders with values from the given properties.

Parameters
beanFactoryToProcess:ConfigurableListableBeanFactory

Doc from org.springframework.beans.factory.config.PropertyResourceConfigurer.processProperties.

the BeanFactory used by the application context

props:Properties

Doc from org.springframework.beans.factory.config.PropertyResourceConfigurer.processProperties.

the Properties to apply

Annotations
@Override
Exceptions
BeansException:

Doc from org.springframework.beans.factory.config.PropertyResourceConfigurer.processProperties.

in case of errors

resolvePlaceholderback to summary
protected String resolvePlaceholder(String placeholder, Properties props, int systemPropertiesMode)

Resolve the given placeholder using the given properties, performing a system properties check according to the given mode.

The default implementation delegates to resolvePlaceholder (placeholder, props) before/after the system properties check.

Subclasses can override this for custom resolution strategies, including customized points for the system properties check.

Parameters
placeholder:String

the placeholder to resolve

props:Properties

the merged properties of this configurer

systemPropertiesMode:int

the system properties mode, according to the constants in this class

Returns:String

the resolved value, of null if none

Annotations
@Nullable
See Also
setSystemPropertiesMode, System#getProperty, resolvePlaceholder(String, java.util.Properties)
resolvePlaceholderback to summary
protected String resolvePlaceholder(String placeholder, Properties props)

Resolve the given placeholder using the given properties. The default implementation simply checks for a corresponding property key.

Subclasses can override this for customized placeholder-to-key mappings or custom resolution strategies, possibly just using the given properties as fallback.

Note that system properties will still be checked before respectively after this method is invoked, according to the system properties mode.

Parameters
placeholder:String

the placeholder to resolve

props:Properties

the merged properties of this configurer

Returns:String

the resolved value, of null if none

Annotations
@Nullable
See Also
setSystemPropertiesMode
resolveSystemPropertyback to summary
protected String resolveSystemProperty(String key)

Resolve the given key as JVM system property, and optionally also as system environment variable if no matching system property has been found.

Parameters
key:String

the placeholder to resolve as system property key

Returns:String

the system property value, or null if not found

Annotations
@Nullable
See Also
setSearchSystemEnvironment, System#getProperty(String), System#getenv(String)
setSearchSystemEnvironmentback to summary
public void setSearchSystemEnvironment(boolean searchSystemEnvironment)

Set whether to search for a matching system environment variable if no matching system property has been found. Only applied when "systemPropertyMode" is active (i.e. "fallback" or "override"), right after checking JVM system properties.

Default is "true". Switch this setting off to never resolve placeholders against system environment variables. Note that it is generally recommended to pass external values in as JVM system properties: This can easily be achieved in a startup script, even for existing environment variables.

See Also
setSystemPropertiesMode, System#getProperty(String), System#getenv(String)
setSystemPropertiesModeback to summary
public void setSystemPropertiesMode(int systemPropertiesMode)

Set how to check system properties: as fallback, as override, or never. For example, will resolve ${user.dir} to the "user.dir" system property.

The default is "fallback": If not being able to resolve a placeholder with the specified properties, a system property will be tried. "override" will check for a system property first, before trying the specified properties. "never" will not check system properties at all.

See Also
SYSTEM_PROPERTIES_MODE_NEVER, SYSTEM_PROPERTIES_MODE_FALLBACK, SYSTEM_PROPERTIES_MODE_OVERRIDE, setSystemPropertiesModeName
setSystemPropertiesModeNameback to summary
public void setSystemPropertiesModeName(String constantName) throws IllegalArgumentException

Set the system property mode by the name of the corresponding constant, e.g. "SYSTEM_PROPERTIES_MODE_OVERRIDE".

Parameters
constantName:String

name of the constant

See Also
setSystemPropertiesMode
org.springframework.beans.factory.config back to summary

private Class PropertyPlaceholderConfigurer.PlaceholderResolvingStringValueResolver

extends Object
implements StringValueResolver
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.PlaceholderResolvingStringValueResolver
All Implemented Interfaces
org.springframework.util.StringValueResolver

Field Summary

Modifier and TypeField and Description
private final PropertyPlaceholderHelper
private final PropertyPlaceholderHelper.PlaceholderResolver

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
resolveStringValue(String
the original String value (never null)
strVal
)

Implements org.springframework.util.StringValueResolver.resolveStringValue.

Resolve the given String value, for example parsing placeholders.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

helperback to summary
private final PropertyPlaceholderHelper helper
resolverback to summary
private final PropertyPlaceholderHelper.PlaceholderResolver resolver

Constructor Detail

PlaceholderResolvingStringValueResolverback to summary
public PlaceholderResolvingStringValueResolver(Properties props)

Method Detail

resolveStringValueback to summary
public String resolveStringValue(String strVal) throws BeansException

Implements org.springframework.util.StringValueResolver.resolveStringValue.

Doc from org.springframework.util.StringValueResolver.resolveStringValue.

Resolve the given String value, for example parsing placeholders.

Parameters
strVal:String

the original String value (never null)

Returns:String

the resolved String value (may be null when resolved to a null value), possibly the original String value itself (in case of no placeholders to resolve or when ignoring unresolvable placeholders)

Annotations
@Override
@Nullable
org.springframework.beans.factory.config back to summary

private final Class PropertyPlaceholderConfigurer.PropertyPlaceholderConfigurerResolver

extends Object
implements PlaceholderResolver
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.PropertyPlaceholderConfigurerResolver
All Implemented Interfaces
org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver

Field Summary

Modifier and TypeField and Description
private final Properties

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
resolvePlaceholder(String
the name of the placeholder to resolve
placeholderName
)

Implements org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver.resolvePlaceholder.

Resolve the supplied placeholder name to the replacement value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

propsback to summary
private final Properties props

Constructor Detail

PropertyPlaceholderConfigurerResolverback to summary
private PropertyPlaceholderConfigurerResolver(Properties props)

Method Detail

resolvePlaceholderback to summary
public String resolvePlaceholder(String placeholderName)

Implements org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver.resolvePlaceholder.

Doc from org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver.resolvePlaceholder.

Resolve the supplied placeholder name to the replacement value.

Parameters
placeholderName:String

the name of the placeholder to resolve

Returns:String

the replacement value, or null if no replacement is to be made

Annotations
@Override
@Nullable