org.springframework.beans.factory.config

Class PropertyPlaceholderConfigurer

    • Field Detail

      • SYSTEM_PROPERTIES_MODE_NEVER

        public static final int SYSTEM_PROPERTIES_MODE_NEVER
        Never check system properties.
        See Also:
        Constant Field Values
      • SYSTEM_PROPERTIES_MODE_FALLBACK

        public static final int SYSTEM_PROPERTIES_MODE_FALLBACK
        Check system properties if not resolvable in the specified properties. This is the default.
        See Also:
        Constant Field Values
      • SYSTEM_PROPERTIES_MODE_OVERRIDE

        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.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PropertyPlaceholderConfigurer

        public PropertyPlaceholderConfigurer()
    • Method Detail

      • setSystemPropertiesModeName

        public void setSystemPropertiesModeName(java.lang.String constantName)
                                         throws java.lang.IllegalArgumentException
        Set the system property mode by the name of the corresponding constant, e.g. "SYSTEM_PROPERTIES_MODE_OVERRIDE".
        Parameters:
        constantName - name of the constant
        Throws:
        java.lang.IllegalArgumentException - if an invalid constant was specified
        See Also:
        setSystemPropertiesMode(int)
      • setSearchSystemEnvironment

        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.

        NOTE: Access to environment variables does not work on the Sun VM 1.4, where the corresponding System.getenv(java.lang.String) 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.

        See Also:
        setSystemPropertiesMode(int), System.getProperty(String), System.getenv(String)
      • resolvePlaceholder

        @Nullable
        protected java.lang.String resolvePlaceholder(java.lang.String placeholder,
                                                                java.util.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 - the placeholder to resolve
        props - the merged properties of this configurer
        systemPropertiesMode - the system properties mode, according to the constants in this class
        Returns:
        the resolved value, of null if none
        See Also:
        setSystemPropertiesMode(int), System.getProperty(java.lang.String), resolvePlaceholder(String, java.util.Properties)
      • resolvePlaceholder

        @Nullable
        protected java.lang.String resolvePlaceholder(java.lang.String placeholder,
                                                                java.util.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 - the placeholder to resolve
        props - the merged properties of this configurer
        Returns:
        the resolved value, of null if none
        See Also:
        setSystemPropertiesMode(int)
      • resolveSystemProperty

        @Nullable
        protected java.lang.String resolveSystemProperty(java.lang.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 - the placeholder to resolve as system property key
        Returns:
        the system property value, or null if not found
        See Also:
        setSearchSystemEnvironment(boolean), System.getProperty(String), System.getenv(String)
      • processProperties

        protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
                                         java.util.Properties props)
                                  throws BeansException
        Visit each bean definition in the given bean factory and attempt to replace ${...} property placeholders with values from the given properties.
        Specified by:
        processProperties in class PropertyResourceConfigurer
        Parameters:
        beanFactoryToProcess - the BeanFactory used by the application context
        props - the Properties to apply
        Throws:
        BeansException - in case of errors