public class RuntimeEnvironmentPropertiesConfigurer
extends org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
implements org.springframework.beans.factory.InitializingBean
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.
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.
<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>
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')
Modifier and Type | Field and Description |
---|---|
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 String |
determinedEnvironment |
protected Set<String> |
environments |
protected RuntimeEnvironmentKeyResolver |
keyResolver |
protected SupportLogger |
logger |
protected Set<org.springframework.core.io.Resource> |
overridableProperyLocations |
protected static String |
PROPERTY_OVERRIDE |
protected Set<org.springframework.core.io.Resource> |
propertyLocations |
protected static String |
SHARED_PROPERTY_OVERRIDE |
protected org.springframework.util.StringValueResolver |
stringValueResolver |
SYSTEM_PROPERTIES_MODE_FALLBACK, SYSTEM_PROPERTIES_MODE_NEVER, SYSTEM_PROPERTIES_MODE_OVERRIDE
DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, ignoreUnresolvablePlaceholders, nullValue, placeholderPrefix, placeholderSuffix, valueSeparator
Constructor and Description |
---|
RuntimeEnvironmentPropertiesConfigurer() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected org.springframework.core.io.Resource[] |
createBroadleafResource() |
protected org.springframework.core.io.Resource[] |
createCommonResource(Set<org.springframework.core.io.Resource> locations) |
protected org.springframework.core.io.Resource |
createOverrideResource() |
protected org.springframework.core.io.Resource[] |
createPropertiesResource(String environment,
Set<org.springframework.core.io.Resource> locations) |
protected org.springframework.core.io.Resource[] |
createSharedCommonResource(Set<org.springframework.core.io.Resource> locations) |
protected org.springframework.core.io.Resource |
createSharedOverrideResource() |
protected org.springframework.core.io.Resource[] |
createSharedPropertiesResource(String environment,
Set<org.springframework.core.io.Resource> locations) |
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 |
setOverridableProperyLocations(Set<org.springframework.core.io.Resource> overridableProperyLocations)
Sets the directory from which to read environment-specific properties
files; note that it must end with a '/'.
|
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 '/'
|
parseStringValue, resolvePlaceholder, resolvePlaceholder, resolveSystemProperty, setSearchSystemEnvironment, setSystemPropertiesMode, setSystemPropertiesModeName
doProcessProperties, setBeanFactory, setBeanName, setIgnoreUnresolvablePlaceholders, setNullValue, setPlaceholderPrefix, setPlaceholderSuffix, setValueSeparator
convertProperties, convertProperty, convertPropertyValue, getOrder, postProcessBeanFactory, setOrder
protected SupportLogger logger
protected static final String SHARED_PROPERTY_OVERRIDE
protected static final String PROPERTY_OVERRIDE
protected static Set<org.springframework.core.io.Resource> blcPropertyLocations
protected static Set<org.springframework.core.io.Resource> defaultPropertyLocations
protected String defaultEnvironment
protected String determinedEnvironment
protected RuntimeEnvironmentKeyResolver keyResolver
protected Set<org.springframework.core.io.Resource> propertyLocations
protected Set<org.springframework.core.io.Resource> overridableProperyLocations
protected org.springframework.util.StringValueResolver stringValueResolver
public RuntimeEnvironmentPropertiesConfigurer()
public void afterPropertiesSet() throws IOException
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
IOException
protected org.springframework.core.io.Resource[] createSharedPropertiesResource(String environment, Set<org.springframework.core.io.Resource> locations) throws IOException
IOException
protected org.springframework.core.io.Resource[] createBroadleafResource() throws IOException
IOException
protected org.springframework.core.io.Resource[] createSharedCommonResource(Set<org.springframework.core.io.Resource> locations) throws IOException
IOException
protected org.springframework.core.io.Resource[] createPropertiesResource(String environment, Set<org.springframework.core.io.Resource> locations) throws IOException
IOException
protected org.springframework.core.io.Resource[] createCommonResource(Set<org.springframework.core.io.Resource> locations) throws IOException
IOException
protected org.springframework.core.io.Resource createSharedOverrideResource() throws IOException
IOException
protected org.springframework.core.io.Resource createOverrideResource() throws IOException
IOException
public String determineEnvironment()
protected void processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws org.springframework.beans.BeansException
processProperties
in class org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
org.springframework.beans.BeansException
public void setDefaultEnvironment(String defaultEnvironment)
public String getDefaultEnvironment()
public void setKeyResolver(RuntimeEnvironmentKeyResolver keyResolver)
public void setEnvironments(Set<String> environments)
public void setPropertyLocations(Set<org.springframework.core.io.Resource> propertyLocations)
public void setOverridableProperyLocations(Set<org.springframework.core.io.Resource> overridableProperyLocations)
overridableProperyLocations
- location containing overridable environment propertiespublic org.springframework.util.StringValueResolver getStringValueResolver()
Copyright © 2014. All rights reserved.