org.broadleafcommerce.common.config
Class RuntimeEnvironmentPropertiesConfigurer
java.lang.Object
org.springframework.core.io.support.PropertiesLoaderSupport
org.springframework.beans.factory.config.PropertyResourceConfigurer
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
org.broadleafcommerce.common.config.RuntimeEnvironmentPropertiesConfigurer
- All Implemented Interfaces:
- 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
| Fields inherited from class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer |
DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, SYSTEM_PROPERTIES_MODE_FALLBACK, SYSTEM_PROPERTIES_MODE_NEVER, SYSTEM_PROPERTIES_MODE_OVERRIDE |
| Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupport |
logger, XML_FILE_EXTENSION |
| Fields inherited from interface org.springframework.core.Ordered |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE |
| Methods inherited from class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer |
parseStringValue, resolvePlaceholder, resolvePlaceholder, resolveSystemProperty, setBeanFactory, setBeanName, setIgnoreUnresolvablePlaceholders, setNullValue, setPlaceholderPrefix, setPlaceholderSuffix, setSearchSystemEnvironment, setSystemPropertiesMode, setSystemPropertiesModeName, 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 |
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
RuntimeEnvironmentPropertiesConfigurer
public RuntimeEnvironmentPropertiesConfigurer()
afterPropertiesSet
public void afterPropertiesSet()
throws IOException
- Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
- Throws:
IOException
compareProperties
protected boolean compareProperties(Properties props1,
Properties props2,
String envInner)
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()
validateProperties
protected void validateProperties()
throws IOException
- Throws:
IOException
mergeProperties
protected Properties mergeProperties(org.springframework.core.io.Resource[] locations)
throws IOException
- Throws:
IOException
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 © 2012. All Rights Reserved.