org.broadleafcommerce.common.config
Class RuntimeEnvironmentPropertiesConfigurer

java.lang.Object
  extended by org.springframework.core.io.support.PropertiesLoaderSupport
      extended by org.springframework.beans.factory.config.PropertyResourceConfigurer
          extended by org.springframework.beans.factory.config.PlaceholderConfigurerSupport
              extended by org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
                  extended by org.broadleafcommerce.common.config.RuntimeEnvironmentPropertiesConfigurer
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.config.BeanFactoryPostProcessor, org.springframework.beans.factory.InitializingBean, org.springframework.core.Ordered, org.springframework.core.PriorityOrdered

public class RuntimeEnvironmentPropertiesConfigurer
extends org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
implements org.springframework.beans.factory.InitializingBean

A property resource configurer that chooses the property file at runtime based on the runtime environment.

Used for choosing properties files based on the current runtime environment, allowing for movement of the same application between multiple runtime environments without rebuilding.

The property replacement semantics of this implementation are identical to PropertyPlaceholderConfigurer, from which this class inherits.

 <bean id="propertyConfigurator" class="frilista.framework.RuntimeEnvironmentPropertiesConfigurer">
        <property name="propertyLocation" value="/WEB-INF/runtime-properties/" />
        <property name="environments">
        <set>
            <value>production</value>
            <value>staging</value>
            <value>integration</value>
            <value>development</value>
        </set>
        </property>
        <property name="defaultEnvironment" value="development"/>
 </bean>
  
The keys of the environment specific properties files are compared to ensure that each property file defines the complete set of keys, in order to avoid environment-specific failures.

An optional RuntimeEnvironmentKeyResolver implementation can be provided, allowing for customization of how the runtime environment is determined. If no implementation is provided, a default of SystemPropertyRuntimeEnvironmentKeyResolver is used (which uses the system property 'runtime.environment')

Author:
Chris Lee

Field Summary
protected static Set<org.springframework.core.io.Resource> blcPropertyLocations
           
protected  String defaultEnvironment
           
protected static Set<String> defaultEnvironments
           
protected static Set<org.springframework.core.io.Resource> defaultPropertyLocations
           
protected  Set<String> environments
           
protected  RuntimeEnvironmentKeyResolver keyResolver
           
protected  Set<org.springframework.core.io.Resource> propertyLocations
           
protected  org.springframework.util.StringValueResolver stringValueResolver
           
 
Fields inherited from class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
SYSTEM_PROPERTIES_MODE_FALLBACK, SYSTEM_PROPERTIES_MODE_NEVER, SYSTEM_PROPERTIES_MODE_OVERRIDE
 
Fields inherited from class org.springframework.beans.factory.config.PlaceholderConfigurerSupport
DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, ignoreUnresolvablePlaceholders, nullValue, placeholderPrefix, placeholderSuffix, valueSeparator
 
Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
localOverride, localProperties, logger, XML_FILE_EXTENSION
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
RuntimeEnvironmentPropertiesConfigurer()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  org.springframework.core.io.Resource[] createBroadleafResource()
           
protected  org.springframework.core.io.Resource[] createCommonResource()
           
protected  org.springframework.core.io.Resource[] createPropertiesResource(String environment)
           
protected  org.springframework.core.io.Resource[] createSharedCommonResource()
           
protected  org.springframework.core.io.Resource[] createSharedPropertiesResource(String environment)
           
 String determineEnvironment()
           
 String getDefaultEnvironment()
           
 org.springframework.util.StringValueResolver getStringValueResolver()
           
protected  void processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
           
 void setDefaultEnvironment(String defaultEnvironment)
          Sets the default environment name, used when the runtime environment cannot be determined.
 void setEnvironments(Set<String> environments)
          Sets the allowed list of runtime environments
 void setKeyResolver(RuntimeEnvironmentKeyResolver keyResolver)
           
 void setPropertyLocations(Set<org.springframework.core.io.Resource> propertyLocations)
          Sets the directory from which to read environment-specific properties files; note that it must end with a '/'
 
Methods inherited from class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
parseStringValue, resolvePlaceholder, resolvePlaceholder, resolveSystemProperty, setSearchSystemEnvironment, setSystemPropertiesMode, setSystemPropertiesModeName
 
Methods inherited from class org.springframework.beans.factory.config.PlaceholderConfigurerSupport
doProcessProperties, setBeanFactory, setBeanName, setIgnoreUnresolvablePlaceholders, setNullValue, setPlaceholderPrefix, setPlaceholderSuffix, setValueSeparator
 
Methods inherited from class org.springframework.beans.factory.config.PropertyResourceConfigurer
convertProperties, convertProperty, convertPropertyValue, getOrder, postProcessBeanFactory, setOrder
 
Methods inherited from class org.springframework.core.io.support.PropertiesLoaderSupport
loadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultEnvironments

protected static Set<String> defaultEnvironments

blcPropertyLocations

protected static Set<org.springframework.core.io.Resource> blcPropertyLocations

defaultPropertyLocations

protected static Set<org.springframework.core.io.Resource> defaultPropertyLocations

defaultEnvironment

protected String defaultEnvironment

keyResolver

protected RuntimeEnvironmentKeyResolver keyResolver

environments

protected Set<String> environments

propertyLocations

protected Set<org.springframework.core.io.Resource> propertyLocations

stringValueResolver

protected org.springframework.util.StringValueResolver stringValueResolver
Constructor Detail

RuntimeEnvironmentPropertiesConfigurer

public RuntimeEnvironmentPropertiesConfigurer()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws IOException
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
IOException

createSharedPropertiesResource

protected org.springframework.core.io.Resource[] createSharedPropertiesResource(String environment)
                                                                         throws IOException
Throws:
IOException

createBroadleafResource

protected org.springframework.core.io.Resource[] createBroadleafResource()
                                                                  throws IOException
Throws:
IOException

createSharedCommonResource

protected org.springframework.core.io.Resource[] createSharedCommonResource()
                                                                     throws IOException
Throws:
IOException

createPropertiesResource

protected org.springframework.core.io.Resource[] createPropertiesResource(String environment)
                                                                   throws IOException
Throws:
IOException

createCommonResource

protected org.springframework.core.io.Resource[] createCommonResource()
                                                               throws IOException
Throws:
IOException

determineEnvironment

public String determineEnvironment()

processProperties

protected void processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactoryToProcess,
                                 Properties props)
                          throws org.springframework.beans.BeansException
Overrides:
processProperties in class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
Throws:
org.springframework.beans.BeansException

setDefaultEnvironment

public void setDefaultEnvironment(String defaultEnvironment)
Sets the default environment name, used when the runtime environment cannot be determined.


getDefaultEnvironment

public String getDefaultEnvironment()

setKeyResolver

public void setKeyResolver(RuntimeEnvironmentKeyResolver keyResolver)

setEnvironments

public void setEnvironments(Set<String> environments)
Sets the allowed list of runtime environments


setPropertyLocations

public void setPropertyLocations(Set<org.springframework.core.io.Resource> propertyLocations)
Sets the directory from which to read environment-specific properties files; note that it must end with a '/'


getStringValueResolver

public org.springframework.util.StringValueResolver getStringValueResolver()


Copyright © 2013. All Rights Reserved.