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 java.util.Set<org.springframework.core.io.Resource> |
blcPropertyLocations |
protected java.lang.String |
defaultEnvironment |
protected static java.util.Set<java.lang.String> |
defaultEnvironments |
protected static java.util.Set<org.springframework.core.io.Resource> |
defaultPropertyLocations |
protected java.lang.String |
determinedEnvironment |
protected java.util.Set<java.lang.String> |
environments |
protected RuntimeEnvironmentKeyResolver |
keyResolver |
protected SupportLogger |
logger |
protected java.util.Set<org.springframework.core.io.Resource> |
overridableProperyLocations |
protected static java.lang.String |
PROPERTY_OVERRIDE |
protected java.util.Set<org.springframework.core.io.Resource> |
propertyLocations |
protected static java.lang.String |
SHARED_PROPERTY_OVERRIDE |
protected org.springframework.util.StringValueResolver |
stringValueResolver |
SYSTEM_PROPERTIES_MODE_FALLBACK, SYSTEM_PROPERTIES_MODE_NEVER, SYSTEM_PROPERTIES_MODE_OVERRIDEDEFAULT_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() |
protected org.springframework.core.io.Resource |
createOverrideResource() |
protected org.springframework.core.io.Resource[] |
createPropertiesResource(java.lang.String environment) |
protected org.springframework.core.io.Resource[] |
createSharedCommonResource() |
protected org.springframework.core.io.Resource |
createSharedOverrideResource() |
protected org.springframework.core.io.Resource[] |
createSharedPropertiesResource(java.lang.String environment) |
java.lang.String |
determineEnvironment() |
java.lang.String |
getDefaultEnvironment() |
org.springframework.util.StringValueResolver |
getStringValueResolver() |
protected void |
processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactoryToProcess,
java.util.Properties props) |
void |
setDefaultEnvironment(java.lang.String defaultEnvironment)
Sets the default environment name, used when the runtime environment
cannot be determined.
|
void |
setEnvironments(java.util.Set<java.lang.String> environments)
Sets the allowed list of runtime environments
|
void |
setKeyResolver(RuntimeEnvironmentKeyResolver keyResolver) |
void |
setOverridableProperyLocations(java.util.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(java.util.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, setSystemPropertiesModeNamedoProcessProperties, setBeanFactory, setBeanName, setIgnoreUnresolvablePlaceholders, setNullValue, setPlaceholderPrefix, setPlaceholderSuffix, setValueSeparatorconvertProperties, convertProperty, convertPropertyValue, getOrder, postProcessBeanFactory, setOrderprotected SupportLogger logger
protected static final java.lang.String SHARED_PROPERTY_OVERRIDE
protected static final java.lang.String PROPERTY_OVERRIDE
protected static java.util.Set<java.lang.String> defaultEnvironments
protected static java.util.Set<org.springframework.core.io.Resource> blcPropertyLocations
protected static java.util.Set<org.springframework.core.io.Resource> defaultPropertyLocations
protected java.lang.String defaultEnvironment
protected java.lang.String determinedEnvironment
protected RuntimeEnvironmentKeyResolver keyResolver
protected java.util.Set<java.lang.String> environments
protected java.util.Set<org.springframework.core.io.Resource> propertyLocations
protected java.util.Set<org.springframework.core.io.Resource> overridableProperyLocations
protected org.springframework.util.StringValueResolver stringValueResolver
public RuntimeEnvironmentPropertiesConfigurer()
public void afterPropertiesSet()
throws java.io.IOException
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.io.IOExceptionprotected org.springframework.core.io.Resource[] createSharedPropertiesResource(java.lang.String environment)
throws java.io.IOException
java.io.IOExceptionprotected org.springframework.core.io.Resource[] createBroadleafResource()
throws java.io.IOException
java.io.IOExceptionprotected org.springframework.core.io.Resource[] createSharedCommonResource()
throws java.io.IOException
java.io.IOExceptionprotected org.springframework.core.io.Resource[] createPropertiesResource(java.lang.String environment)
throws java.io.IOException
java.io.IOExceptionprotected org.springframework.core.io.Resource[] createCommonResource()
throws java.io.IOException
java.io.IOExceptionprotected org.springframework.core.io.Resource createSharedOverrideResource()
throws java.io.IOException
java.io.IOExceptionprotected org.springframework.core.io.Resource createOverrideResource()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String determineEnvironment()
protected void processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactoryToProcess,
java.util.Properties props)
throws org.springframework.beans.BeansException
processProperties in class org.springframework.beans.factory.config.PropertyPlaceholderConfigurerorg.springframework.beans.BeansExceptionpublic void setDefaultEnvironment(java.lang.String defaultEnvironment)
public java.lang.String getDefaultEnvironment()
public void setKeyResolver(RuntimeEnvironmentKeyResolver keyResolver)
public void setEnvironments(java.util.Set<java.lang.String> environments)
public void setPropertyLocations(java.util.Set<org.springframework.core.io.Resource> propertyLocations)
public void setOverridableProperyLocations(java.util.Set<org.springframework.core.io.Resource> overridableProperyLocations)
overridableProperyLocations - location containing overridable environment propertiespublic org.springframework.util.StringValueResolver getStringValueResolver()
Copyright © 2018. All Rights Reserved.