spring-framework / org.springframework.beans.factory.config / PropertyPlaceholderConfigurer

PropertyPlaceholderConfigurer

open class PropertyPlaceholderConfigurer : PlaceholderConfigurerSupport

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

As of Spring 3.1, org.springframework.context.support.PropertySourcesPlaceholderConfigurer should be used preferentially over this implementation; it is more flexible through taking advantage of the org.springframework.core.env.Environment and org.springframework.core.env.PropertySource mechanisms also made available in Spring 3.1.

PropertyPlaceholderConfigurer is still appropriate for use when:

Prior to Spring 3.1, the <context:property-placeholder/> namespace element registered an instance of PropertyPlaceholderConfigurer. It will still do so if using the spring-context-3.0.xsd definition of the namespace. That is, you can preserve registration of PropertyPlaceholderConfigurer through the namespace, even if using Spring 3.1; simply do not update your xsi:schemaLocation and continue using the 3.0 XSD.

Author
Juergen Hoeller

Author
Chris Beams

Since
02.10.2003

See Also
#setSystemPropertiesModeNamePlaceholderConfigurerSupportPropertyOverrideConfigurerorg.springframework.context.support.PropertySourcesPlaceholderConfigurer

Constructors

<init>

PropertyPlaceholderConfigurer()

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

As of Spring 3.1, org.springframework.context.support.PropertySourcesPlaceholderConfigurer should be used preferentially over this implementation; it is more flexible through taking advantage of the org.springframework.core.env.Environment and org.springframework.core.env.PropertySource mechanisms also made available in Spring 3.1.

PropertyPlaceholderConfigurer is still appropriate for use when:

  • the spring-context module is not available (i.e., one is using Spring's BeanFactory API as opposed to ApplicationContext).
  • 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's Environment; however, exact preservation of functionality may be maintained by continuing to use PropertyPlaceholderConfigurer.

Prior to Spring 3.1, the <context:property-placeholder/> namespace element registered an instance of PropertyPlaceholderConfigurer. It will still do so if using the spring-context-3.0.xsd definition of the namespace. That is, you can preserve registration of PropertyPlaceholderConfigurer through the namespace, even if using Spring 3.1; simply do not update your xsi:schemaLocation and continue using the 3.0 XSD.

Properties

SYSTEM_PROPERTIES_MODE_FALLBACK

static val SYSTEM_PROPERTIES_MODE_FALLBACK: Int

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

SYSTEM_PROPERTIES_MODE_NEVER

static val SYSTEM_PROPERTIES_MODE_NEVER: Int

Never check system properties.

SYSTEM_PROPERTIES_MODE_OVERRIDE

static val SYSTEM_PROPERTIES_MODE_OVERRIDE: Int

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

Functions

setSearchSystemEnvironment

open fun setSearchSystemEnvironment(searchSystemEnvironment: Boolean): Unit

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.

NOTE: Access to environment variables does not work on the Sun VM 1.4, where the corresponding System#getenv support was disabled - before it eventually got re-enabled for the Sun VM 1.5. Please upgrade to 1.5 (or higher) if you intend to rely on the environment variable support.

setSystemPropertiesMode

open fun setSystemPropertiesMode(systemPropertiesMode: Int): Unit

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.

setSystemPropertiesModeName

open fun setSystemPropertiesModeName(constantName: String): Unit

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

Inheritors

PreferencesPlaceholderConfigurer

open class PreferencesPlaceholderConfigurer : PropertyPlaceholderConfigurer, InitializingBean

Subclass of PropertyPlaceholderConfigurer that supports JDK 1.4's Preferences API (java.util.prefs).

Tries to resolve placeholders as keys first in the user preferences, then in the system preferences, then in this configurer's properties. Thus, behaves like PropertyPlaceholderConfigurer if no corresponding preferences defined.

Supports custom paths for the system and user preferences trees. Also supports custom paths specified in placeholders ("myPath/myPlaceholderKey"). Uses the respective root node if not specified.