Class PropertyPlaceholderConfigurer
- All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, BeanFactoryPostProcessor, Ordered, PriorityOrdered
- Direct Known Subclasses:
PreferencesPlaceholderConfigurer
PlaceholderConfigurerSupport subclass that resolves ${...} placeholders against
local properties and/or system properties
and environment variables.
PropertyPlaceholderConfigurer is still appropriate for use when:
- the
spring-contextmodule is not available (i.e., one is using Spring'sBeanFactoryAPI as opposed toApplicationContext). - existing configuration makes use of the
"systemPropertiesMode"and/or"systemPropertiesModeName"properties. Users are encouraged to move away from using these settings, and rather configure property source search order through the container'sEnvironment; however, exact preservation of functionality may be maintained by continuing to usePropertyPlaceholderConfigurer.
- Since:
- 02.10.2003
- Author:
- Juergen Hoeller, Chris Beams, Sam Brannen
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDeprecated, for removal: This API element is subject to removal in a future version.Check system properties if not resolvable in the specified properties.static final intDeprecated, for removal: This API element is subject to removal in a future version.Never check system properties.static final intDeprecated, for removal: This API element is subject to removal in a future version.Check system properties first, before trying the specified properties.Fields inherited from class PlaceholderConfigurerSupport
DEFAULT_ESCAPE_CHARACTER, DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, escapeCharacter, ignoreUnresolvablePlaceholders, nullValue, placeholderPrefix, placeholderSuffix, trimValues, valueSeparatorFields inherited from class PropertiesLoaderSupport
localOverride, localProperties, loggerFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprocessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) Deprecated, for removal: This API element is subject to removal in a future version.Visit each bean definition in the given bean factory and attempt to replace ${...} property placeholders with values from the given properties.resolvePlaceholder(String placeholder, Properties props) Deprecated, for removal: This API element is subject to removal in a future version.Resolve the given placeholder using the given properties.resolvePlaceholder(String placeholder, Properties props, int systemPropertiesMode) Deprecated, for removal: This API element is subject to removal in a future version.Resolve the given placeholder using the given properties, performing a system properties check according to the given mode.Deprecated, for removal: This API element is subject to removal in a future version.Resolve the given key as JVM system property, and optionally also as system environment variable if no matching system property has been found.voidsetSearchSystemEnvironment(boolean searchSystemEnvironment) Deprecated, for removal: This API element is subject to removal in a future version.Set whether to search for a matching system environment variable if no matching system property has been found.voidsetSystemPropertiesMode(int systemPropertiesMode) Deprecated, for removal: This API element is subject to removal in a future version.Set how to check system properties: as fallback, as override, or never.voidsetSystemPropertiesModeName(String constantName) Deprecated, for removal: This API element is subject to removal in a future version.Set the system property mode by the name of the corresponding constant, for example, "SYSTEM_PROPERTIES_MODE_OVERRIDE".Methods inherited from class PlaceholderConfigurerSupport
doProcessProperties, setBeanFactory, setBeanName, setEscapeCharacter, setIgnoreUnresolvablePlaceholders, setnullValue, setPlaceholderPrefix, setPlaceholderSuffix, setTrimValues, setValueSeparatorMethods inherited from class PropertyResourceConfigurer
convertProperties, convertProperty, convertPropertyValue, getOrder, postProcessBeanFactory, setOrderMethods inherited from class PropertiesLoaderSupport
loadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
-
Field Details
-
SYSTEM_PROPERTIES_MODE_NEVER
public static final int SYSTEM_PROPERTIES_MODE_NEVERDeprecated, for removal: This API element is subject to removal in a future version.Never check system properties.- See Also:
-
SYSTEM_PROPERTIES_MODE_FALLBACK
public static final int SYSTEM_PROPERTIES_MODE_FALLBACKDeprecated, for removal: This API element is subject to removal in a future version.Check system properties if not resolvable in the specified properties. This is the default.- See Also:
-
SYSTEM_PROPERTIES_MODE_OVERRIDE
public static final int SYSTEM_PROPERTIES_MODE_OVERRIDEDeprecated, for removal: This API element is subject to removal in a future version.Check system properties first, before trying the specified properties. This allows system properties to override any other property source.- See Also:
-
-
Constructor Details
-
PropertyPlaceholderConfigurer
public PropertyPlaceholderConfigurer()Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
setSystemPropertiesModeName
Deprecated, for removal: This API element is subject to removal in a future version.Set the system property mode by the name of the corresponding constant, for example, "SYSTEM_PROPERTIES_MODE_OVERRIDE".- Parameters:
constantName- name of the constant- Throws:
IllegalArgumentException- See Also:
-
setSystemPropertiesMode
public void setSystemPropertiesMode(int systemPropertiesMode) Deprecated, for removal: This API element is subject to removal in a future version.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:
-
setSearchSystemEnvironment
public void setSearchSystemEnvironment(boolean searchSystemEnvironment) Deprecated, for removal: This API element is subject to removal in a future version.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:
-
resolvePlaceholder
protected @nullable String resolvePlaceholder(String placeholder, Properties props, int systemPropertiesMode) Deprecated, for removal: This API element is subject to removal in a future version.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- the placeholder to resolveprops- the merged properties of this configurersystemPropertiesMode- the system properties mode, according to the constants in this class- Returns:
- the resolved value, of null if none
- See Also:
-
resolvePlaceholder
Deprecated, for removal: This API element is subject to removal in a future version.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- the placeholder to resolveprops- the merged properties of this configurer- Returns:
- the resolved value, of
nullif none - See Also:
-
resolveSystemProperty
Deprecated, for removal: This API element is subject to removal in a future version.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- the placeholder to resolve as system property key- Returns:
- the system property value, or
nullif not found - See Also:
-
processProperties
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException Deprecated, for removal: This API element is subject to removal in a future version.Visit each bean definition in the given bean factory and attempt to replace ${...} property placeholders with values from the given properties.- Specified by:
processPropertiesin classPropertyResourceConfigurer- Parameters:
beanFactoryToProcess- the BeanFactory used by the application contextprops- the Properties to apply- Throws:
BeansException- in case of errors
-
org.springframework.context.support.PropertySourcesPlaceholderConfigurerinstead which is more flexible through taking advantage of theEnvironmentandPropertySourcemechanisms.