Top Description Fields Constructors Methods
org.springframework.core.env

public abstract Class AbstractEnvironment

extends Object
implements ConfigurableEnvironment
Class Inheritance
All Implemented Interfaces
org.springframework.core.env.ConfigurableEnvironment, org.springframework.core.env.ConfigurablePropertyResolver, org.springframework.core.env.PropertyResolver, org.springframework.core.env.Environment
Known Direct Subclasses
org.springframework.core.env.StandardEnvironment
Imports
java.util.Arrays, .Collections, .LinkedHashSet, .Map, .Set, org.apache.commons.logging.Log, .LogFactory, org.springframework.core.SpringProperties, org.springframework.core.convert.support.ConfigurableConversionService, org.springframework.lang.Nullable, org.springframework.util.Assert, .ObjectUtils, .StringUtils

Abstract base class for Environment implementations. Supports the notion of reserved default profile names and enables specifying active and default profiles through the ACTIVE_PROFILES_PROPERTY_NAME and DEFAULT_PROFILES_PROPERTY_NAME properties.

Concrete subclasses differ primarily on which PropertySource objects they add by default. AbstractEnvironment adds none. Subclasses should contribute property sources through the protected customizePropertySources(MutablePropertySources) hook, while clients should customize using ConfigurableEnvironment#getPropertySources() and working against the MutablePropertySources API. See ConfigurableEnvironment javadoc for usage examples.

Authors
Chris Beams, Juergen Hoeller, Phillip Webb
Since
3.1
See Also
ConfigurableEnvironment, StandardEnvironment

Field Summary

Modifier and TypeField and Description
public static final String
ACTIVE_PROFILES_PROPERTY_NAME

Name of the property to set to specify active profiles: spring.profiles.active.

private final Set<String>
public static final String
DEFAULT_PROFILES_PROPERTY_NAME

Name of the property to set to specify profiles that are active by default: spring.profiles.default.

private final Set<String>
public static final String
IGNORE_GETENV_PROPERTY_NAME

System property that instructs Spring to ignore system environment variables, i.e. to never attempt to retrieve such a variable via System#getenv().

protected final Log
private final ConfigurablePropertyResolver
private final MutablePropertySources
public static final String
RESERVED_DEFAULT_PROFILE_NAME

Name of the reserved default profile name: default.

Constructor Summary

AccessConstructor and Description
public
AbstractEnvironment()

Create a new Environment instance, calling back to customizePropertySources(MutablePropertySources) during construction to allow subclasses to contribute or manipulate PropertySource instances as appropriate.

protected
AbstractEnvironment(MutablePropertySources
property sources to use
propertySources
)

Create a new Environment instance with a specific MutablePropertySources instance, calling back to customizePropertySources(MutablePropertySources) during construction to allow subclasses to contribute or manipulate PropertySource instances as appropriate.

Method Summary

Modifier and TypeMethod and Description
public boolean
acceptsProfiles(String... profiles)

Implements org.springframework.core.env.Environment.acceptsProfiles.

Deprecated

Determine whether one or more of the given profiles is active — or in the case of no explicit active profiles, whether one or more of the given profiles is included in the set of default profiles.

public boolean
acceptsProfiles(Profiles profiles)

Implements org.springframework.core.env.Environment.acceptsProfiles.

Determine whether the given Profiles predicate matches the active profiles — or in the case of no explicit active profiles, whether the given Profiles predicate matches the default profiles.

public void
addActiveProfile(String profile)

Implements org.springframework.core.env.ConfigurableEnvironment.addActiveProfile.

Add a profile to the current set of active profiles.

public boolean
containsProperty(String key)

Implements org.springframework.core.env.PropertyResolver.containsProperty.

Return whether the given property key is available for resolution, i.e. if the value for the given key is not null.

protected ConfigurablePropertyResolver
createPropertyResolver(MutablePropertySources propertySources)

Factory method used to create the ConfigurablePropertyResolver instance used by the Environment.

protected void
customizePropertySources(MutablePropertySources propertySources)

Customize the set of PropertySource objects to be searched by this Environment during calls to getProperty(String) and related methods.

protected Set<String>
doGetActiveProfiles()

Return the set of active profiles as explicitly set through setActiveProfiles or if the current set of active profiles is empty, check for the presence of doGetActiveProfilesProperty() and assign its value to the set of active profiles.

protected String
doGetActiveProfilesProperty()

Return the property value for the active profiles.

protected Set<String>
doGetDefaultProfiles()

Return the set of default profiles explicitly set via setDefaultProfiles(String...) or if the current set of default profiles consists only of reserved default profiles, then check for the presence of doGetActiveProfilesProperty() and assign its value (if any) to the set of default profiles.

protected String
doGetDefaultProfilesProperty()

Return the property value for the default profiles.

public String[]
getActiveProfiles()

Implements org.springframework.core.env.Environment.getActiveProfiles.

Return the set of profiles explicitly made active for this environment.

public ConfigurableConversionService
public String[]
getDefaultProfiles()

Implements org.springframework.core.env.Environment.getDefaultProfiles.

Return the set of profiles to be active by default when no active profiles have been set explicitly.

public String
getProperty(String
the property name to resolve
key
)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or null if the key cannot be resolved.

public String
getProperty(String
the property name to resolve
key
,
String
the default value to return if no value is found
defaultValue
)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.

public <T> T
getProperty(String
the property name to resolve
key
,
Class<T>
the expected type of the property value
targetType
)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or null if the key cannot be resolved.

public <T> T
getProperty(String
the property name to resolve
key
,
Class<T>
the expected type of the property value
targetType
,
T
the default value to return if no value is found
defaultValue
)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.

protected final ConfigurablePropertyResolver
public MutablePropertySources
getPropertySources()

Implements org.springframework.core.env.ConfigurableEnvironment.getPropertySources.

Return the PropertySources for this Environment in mutable form, allowing for manipulation of the set of PropertySource objects that should be searched when resolving properties against this Environment object.

public String
getRequiredProperty(String key)

Implements org.springframework.core.env.PropertyResolver.getRequiredProperty.

Return the property value associated with the given key (never null).

public <T> T
getRequiredProperty(String key, Class<T> targetType)

Implements org.springframework.core.env.PropertyResolver.getRequiredProperty.

Return the property value associated with the given key, converted to the given targetType (never null).

protected Set<String>
getReservedDefaultProfiles()

Return the set of reserved default profile names.

public Map<String, Object>
public Map<String, Object>
protected boolean
isProfileActive(String profile)

Return whether the given profile is active, or if active profiles are empty whether the profile should be active by default.

public void
merge(ConfigurableEnvironment
the environment to merge with
parent
)

Implements org.springframework.core.env.ConfigurableEnvironment.merge.

Append the given parent environment's active profiles, default profiles and property sources to this (child) environment's respective collections of each.

public String
resolvePlaceholders(String
the String to resolve
text
)

Implements org.springframework.core.env.PropertyResolver.resolvePlaceholders.

Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty.

public String
resolveRequiredPlaceholders(String text)

Implements org.springframework.core.env.PropertyResolver.resolveRequiredPlaceholders.

Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty.

public void
setActiveProfiles(String... profiles)

Implements org.springframework.core.env.ConfigurableEnvironment.setActiveProfiles.

Specify the set of profiles active for this Environment.

public void
public void
setDefaultProfiles(String... profiles)

Implements org.springframework.core.env.ConfigurableEnvironment.setDefaultProfiles.

Specify the set of profiles to be made active by default if no other profiles are explicitly made active through setActiveProfiles.

public void
setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setIgnoreUnresolvableNestedPlaceholders.

Set whether to throw an exception when encountering an unresolvable placeholder nested within the value of a given property.

public void
setPlaceholderPrefix(String placeholderPrefix)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderPrefix.

Set the prefix that placeholders replaced by this resolver must begin with.

public void
setPlaceholderSuffix(String placeholderSuffix)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderSuffix.

Set the suffix that placeholders replaced by this resolver must end with.

public void
setRequiredProperties(String... requiredProperties)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setRequiredProperties.

Specify which properties must be present, to be verified by validateRequiredProperties().

public void
setValueSeparator(String valueSeparator)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setValueSeparator.

Specify the separating character between the placeholders replaced by this resolver and their associated default value, or null if no such special character should be processed as a value separator.

protected boolean
suppressGetenvAccess()

Determine whether to suppress System#getenv()/System#getenv(String) access for the purposes of getSystemEnvironment().

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

protected void
validateProfile(String profile)

Validate the given profile, called internally prior to adding to the set of active or default profiles.

public void
validateRequiredProperties()

Implements org.springframework.core.env.ConfigurablePropertyResolver.validateRequiredProperties.

Validate that each of the properties specified by setRequiredProperties is present and resolves to a non-null value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ACTIVE_PROFILES_PROPERTY_NAMEback to summary
public static final String ACTIVE_PROFILES_PROPERTY_NAME

Name of the property to set to specify active profiles: spring.profiles.active.

The value may be comma delimited.

Note that certain shell environments such as Bash disallow the use of the period character in variable names. Assuming that Spring's SystemEnvironmentPropertySource is in use, this property may be specified as an environment variable named SPRING_PROFILES_ACTIVE.

See Also
ConfigurableEnvironment#setActiveProfiles
activeProfilesback to summary
private final Set<String> activeProfiles
DEFAULT_PROFILES_PROPERTY_NAMEback to summary
public static final String DEFAULT_PROFILES_PROPERTY_NAME

Name of the property to set to specify profiles that are active by default: spring.profiles.default.

The value may be comma delimited.

Note that certain shell environments such as Bash disallow the use of the period character in variable names. Assuming that Spring's SystemEnvironmentPropertySource is in use, this property may be specified as an environment variable named SPRING_PROFILES_DEFAULT.

See Also
ConfigurableEnvironment#setDefaultProfiles
defaultProfilesback to summary
private final Set<String> defaultProfiles
IGNORE_GETENV_PROPERTY_NAMEback to summary
public static final String IGNORE_GETENV_PROPERTY_NAME

System property that instructs Spring to ignore system environment variables, i.e. to never attempt to retrieve such a variable via System#getenv().

The default is "false", falling back to system environment variable checks if a Spring environment property (e.g. a placeholder in a configuration String) isn't resolvable otherwise. Consider switching this flag to "true" if you experience log warnings from getenv calls coming from Spring.

See Also
suppressGetenvAccess()
loggerback to summary
protected final Log logger
propertyResolverback to summary
private final ConfigurablePropertyResolver propertyResolver
propertySourcesback to summary
private final MutablePropertySources propertySources
RESERVED_DEFAULT_PROFILE_NAMEback to summary
public static final String RESERVED_DEFAULT_PROFILE_NAME

Name of the reserved default profile name: default.

If no default profile names are explicitly set and no active profile names are explicitly set, this profile will automatically be activated by default.

See Also
getReservedDefaultProfiles, ConfigurableEnvironment#setDefaultProfiles, ConfigurableEnvironment#setActiveProfiles, AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME, AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME

Constructor Detail

AbstractEnvironmentback to summary
public AbstractEnvironment()

Create a new Environment instance, calling back to customizePropertySources(MutablePropertySources) during construction to allow subclasses to contribute or manipulate PropertySource instances as appropriate.

See Also
customizePropertySources(MutablePropertySources)
AbstractEnvironmentback to summary
protected AbstractEnvironment(MutablePropertySources propertySources)

Create a new Environment instance with a specific MutablePropertySources instance, calling back to customizePropertySources(MutablePropertySources) during construction to allow subclasses to contribute or manipulate PropertySource instances as appropriate.

Parameters
propertySources:MutablePropertySources

property sources to use

Since
5.3.4
See Also
customizePropertySources(MutablePropertySources)

Method Detail

acceptsProfilesback to summary
public boolean acceptsProfiles(String... profiles)

Implements org.springframework.core.env.Environment.acceptsProfiles.

Doc from org.springframework.core.env.Environment.acceptsProfiles.

Deprecated

Determine whether one or more of the given profiles is active — or in the case of no explicit active profiles, whether one or more of the given profiles is included in the set of default profiles.

If a profile begins with '!' the logic is inverted, meaning this method will return true if the given profile is not active. For example, env.acceptsProfiles("p1", "!p2") will return true if profile 'p1' is active or 'p2' is not active.

Annotations
@Override
@Deprecated
acceptsProfilesback to summary
public boolean acceptsProfiles(Profiles profiles)

Implements org.springframework.core.env.Environment.acceptsProfiles.

Doc from org.springframework.core.env.Environment.acceptsProfiles.

Determine whether the given Profiles predicate matches the active profiles — or in the case of no explicit active profiles, whether the given Profiles predicate matches the default profiles.

If you wish provide profile expressions directly as strings, use matchesProfiles(String...) instead.

Annotations
@Override
addActiveProfileback to summary
public void addActiveProfile(String profile)

Implements org.springframework.core.env.ConfigurableEnvironment.addActiveProfile.

Doc from org.springframework.core.env.ConfigurableEnvironment.addActiveProfile.

Add a profile to the current set of active profiles.

Annotations
@Override
containsPropertyback to summary
public boolean containsProperty(String key)

Implements org.springframework.core.env.PropertyResolver.containsProperty.

Doc from org.springframework.core.env.PropertyResolver.containsProperty.

Return whether the given property key is available for resolution, i.e. if the value for the given key is not null.

Annotations
@Override
createPropertyResolverback to summary
protected ConfigurablePropertyResolver createPropertyResolver(MutablePropertySources propertySources)

Factory method used to create the ConfigurablePropertyResolver instance used by the Environment.

Since
5.3.4
See Also
getPropertyResolver()
customizePropertySourcesback to summary
protected void customizePropertySources(MutablePropertySources propertySources)

Customize the set of PropertySource objects to be searched by this Environment during calls to getProperty(String) and related methods.

Subclasses that override this method are encouraged to add property sources using MutablePropertySources#addLast(PropertySource) such that further subclasses may call super.customizePropertySources() with predictable results. For example:

public class Level1Environment extends AbstractEnvironment {
    @Override
    protected void customizePropertySources(MutablePropertySources propertySources) {
        super.customizePropertySources(propertySources); // no-op from base class
        propertySources.addLast(new PropertySourceA(...));
        propertySources.addLast(new PropertySourceB(...));
    }
}

public class Level2Environment extends Level1Environment {
    @Override
    protected void customizePropertySources(MutablePropertySources propertySources) {
        super.customizePropertySources(propertySources); // add all from superclass
        propertySources.addLast(new PropertySourceC(...));
        propertySources.addLast(new PropertySourceD(...));
    }
}

In this arrangement, properties will be resolved against sources A, B, C, D in that order. That is to say that property source "A" has precedence over property source "D". If the Level2Environment subclass wished to give property sources C and D higher precedence than A and B, it could simply call super.customizePropertySources after, rather than before adding its own:

public class Level2Environment extends Level1Environment {
    @Override
    protected void customizePropertySources(MutablePropertySources propertySources) {
        propertySources.addLast(new PropertySourceC(...));
        propertySources.addLast(new PropertySourceD(...));
        super.customizePropertySources(propertySources); // add all from superclass
    }
}

The search order is now C, D, A, B as desired.

Beyond these recommendations, subclasses may use any of the add*, remove, or replace methods exposed by MutablePropertySources in order to create the exact arrangement of property sources desired.

The base implementation registers no property sources.

Note that clients of any ConfigurableEnvironment may further customize property sources via the getPropertySources() accessor, typically within an ApplicationContextInitializer. For example:

ConfigurableEnvironment env = new StandardEnvironment();
env.getPropertySources().addLast(new PropertySourceX(...));

A warning about instance variable access

Instance variables declared in subclasses and having default initial values should not be accessed from within this method. Due to Java object creation lifecycle constraints, any initial value will not yet be assigned when this callback is invoked by the AbstractEnvironment() constructor, which may lead to a NullPointerException or other problems. If you need to access default values of instance variables, leave this method as a no-op and perform property source manipulation and instance variable access directly within the subclass constructor. Note that assigning values to instance variables is not problematic; it is only attempting to read default values that must be avoided.

See Also
MutablePropertySources, PropertySourcesPropertyResolver, org.springframework.context.ApplicationContextInitializer
doGetActiveProfilesback to summary
protected Set<String> doGetActiveProfiles()

Return the set of active profiles as explicitly set through setActiveProfiles or if the current set of active profiles is empty, check for the presence of doGetActiveProfilesProperty() and assign its value to the set of active profiles.

See Also
getActiveProfiles(), doGetActiveProfilesProperty()
doGetActiveProfilesPropertyback to summary
protected String doGetActiveProfilesProperty()

Return the property value for the active profiles.

Annotations
@Nullable
Since
5.3.4
See Also
ACTIVE_PROFILES_PROPERTY_NAME
doGetDefaultProfilesback to summary
protected Set<String> doGetDefaultProfiles()

Return the set of default profiles explicitly set via setDefaultProfiles(String...) or if the current set of default profiles consists only of reserved default profiles, then check for the presence of doGetActiveProfilesProperty() and assign its value (if any) to the set of default profiles.

See Also
AbstractEnvironment(), getDefaultProfiles(), getReservedDefaultProfiles(), doGetDefaultProfilesProperty()
doGetDefaultProfilesPropertyback to summary
protected String doGetDefaultProfilesProperty()

Return the property value for the default profiles.

Annotations
@Nullable
Since
5.3.4
See Also
DEFAULT_PROFILES_PROPERTY_NAME
getActiveProfilesback to summary
public String[] getActiveProfiles()

Implements org.springframework.core.env.Environment.getActiveProfiles.

Doc from org.springframework.core.env.Environment.getActiveProfiles.

Return the set of profiles explicitly made active for this environment. Profiles are used for creating logical groupings of bean definitions to be registered conditionally, for example based on deployment environment. Profiles can be activated by setting "spring.profiles.active" as a system property or by calling ConfigurableEnvironment#setActiveProfiles(String...).

If no profiles have explicitly been specified as active, then any default profiles will automatically be activated.

Annotations
@Override
getConversionServiceback to summary
public ConfigurableConversionService getConversionService()

Implements org.springframework.core.env.ConfigurablePropertyResolver.getConversionService.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.getConversionService.

Return the ConfigurableConversionService used when performing type conversions on properties.

The configurable nature of the returned conversion service allows for the convenient addition and removal of individual Converter instances:

ConfigurableConversionService cs = env.getConversionService();
cs.addConverter(new FooConverter());
Annotations
@Override
getDefaultProfilesback to summary
public String[] getDefaultProfiles()

Implements org.springframework.core.env.Environment.getDefaultProfiles.

Doc from org.springframework.core.env.Environment.getDefaultProfiles.

Return the set of profiles to be active by default when no active profiles have been set explicitly.

Annotations
@Override
getPropertyback to summary
public String getProperty(String key)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Doc from org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or null if the key cannot be resolved.

Parameters
key:String

the property name to resolve

Annotations
@Override
@Nullable
getPropertyback to summary
public String getProperty(String key, String defaultValue)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Doc from org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.

Parameters
key:String

the property name to resolve

defaultValue:String

the default value to return if no value is found

Annotations
@Override
getPropertyback to summary
public <T> T getProperty(String key, Class<T> targetType)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Doc from org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or null if the key cannot be resolved.

Parameters
key:String

the property name to resolve

targetType:Class<T>

the expected type of the property value

Annotations
@Override
@Nullable
getPropertyback to summary
public <T> T getProperty(String key, Class<T> targetType, T defaultValue)

Implements org.springframework.core.env.PropertyResolver.getProperty.

Doc from org.springframework.core.env.PropertyResolver.getProperty.

Return the property value associated with the given key, or defaultValue if the key cannot be resolved.

Parameters
key:String

the property name to resolve

targetType:Class<T>

the expected type of the property value

defaultValue:T

the default value to return if no value is found

Annotations
@Override
getPropertyResolverback to summary
protected final ConfigurablePropertyResolver getPropertyResolver()

Return the ConfigurablePropertyResolver being used by the Environment.

Since
5.3.4
See Also
createPropertyResolver(MutablePropertySources)
getPropertySourcesback to summary
public MutablePropertySources getPropertySources()

Implements org.springframework.core.env.ConfigurableEnvironment.getPropertySources.

Doc from org.springframework.core.env.ConfigurableEnvironment.getPropertySources.

Return the PropertySources for this Environment in mutable form, allowing for manipulation of the set of PropertySource objects that should be searched when resolving properties against this Environment object. The various MutablePropertySources methods such as addFirst, addLast, addBefore and addAfter allow for fine-grained control over property source ordering. This is useful, for example, in ensuring that certain user-defined property sources have search precedence over default property sources such as the set of system properties or the set of system environment variables.

Annotations
@Override
getRequiredPropertyback to summary
public String getRequiredProperty(String key) throws IllegalStateException

Implements org.springframework.core.env.PropertyResolver.getRequiredProperty.

Doc from org.springframework.core.env.PropertyResolver.getRequiredProperty.

Return the property value associated with the given key (never null).

Annotations
@Override
Exceptions
IllegalStateException:
if the key cannot be resolved
getRequiredPropertyback to summary
public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException

Implements org.springframework.core.env.PropertyResolver.getRequiredProperty.

Doc from org.springframework.core.env.PropertyResolver.getRequiredProperty.

Return the property value associated with the given key, converted to the given targetType (never null).

Annotations
@Override
Exceptions
IllegalStateException:
if the given key cannot be resolved
getReservedDefaultProfilesback to summary
protected Set<String> getReservedDefaultProfiles()

Return the set of reserved default profile names. This implementation returns default. Subclasses may override in order to customize the set of reserved names.

See Also
RESERVED_DEFAULT_PROFILE_NAME, doGetDefaultProfiles()
getSystemEnvironmentback to summary
public Map<String, Object> getSystemEnvironment()

Implements org.springframework.core.env.ConfigurableEnvironment.getSystemEnvironment.

Doc from org.springframework.core.env.ConfigurableEnvironment.getSystemEnvironment.

Return the value of System#getenv().

Note that most Environment implementations will include this system environment map as a default PropertySource to be searched. Therefore, it is recommended that this method not be used directly unless bypassing other property sources is expressly intended.

Annotations
@Override
@SuppressWarnings:rawtypes, unchecked
getSystemPropertiesback to summary
public Map<String, Object> getSystemProperties()

Implements org.springframework.core.env.ConfigurableEnvironment.getSystemProperties.

Doc from org.springframework.core.env.ConfigurableEnvironment.getSystemProperties.

Return the value of System#getProperties().

Note that most Environment implementations will include this system properties map as a default PropertySource to be searched. Therefore, it is recommended that this method not be used directly unless bypassing other property sources is expressly intended.

Annotations
@Override
@SuppressWarnings:rawtypes, unchecked
isProfileActiveback to summary
protected boolean isProfileActive(String profile)

Return whether the given profile is active, or if active profiles are empty whether the profile should be active by default.

Exceptions
IllegalArgumentException:
per validateProfile(String)
mergeback to summary
public void merge(ConfigurableEnvironment parent)

Implements org.springframework.core.env.ConfigurableEnvironment.merge.

Doc from org.springframework.core.env.ConfigurableEnvironment.merge.

Append the given parent environment's active profiles, default profiles and property sources to this (child) environment's respective collections of each.

For any identically-named PropertySource instance existing in both parent and child, the child instance is to be preserved and the parent instance discarded. This has the effect of allowing overriding of property sources by the child as well as avoiding redundant searches through common property source types, e.g. system environment and system properties.

Active and default profile names are also filtered for duplicates, to avoid confusion and redundant storage.

The parent environment remains unmodified in any case. Note that any changes to the parent environment occurring after the call to merge will not be reflected in the child. Therefore, care should be taken to configure parent property sources and profile information prior to calling merge.

Parameters
parent:ConfigurableEnvironment

the environment to merge with

Annotations
@Override
resolvePlaceholdersback to summary
public String resolvePlaceholders(String text)

Implements org.springframework.core.env.PropertyResolver.resolvePlaceholders.

Doc from org.springframework.core.env.PropertyResolver.resolvePlaceholders.

Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty. Unresolvable placeholders with no default value are ignored and passed through unchanged.

Parameters
text:String

the String to resolve

Returns:String

the resolved String (never null)

Annotations
@Override
resolveRequiredPlaceholdersback to summary
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException

Implements org.springframework.core.env.PropertyResolver.resolveRequiredPlaceholders.

Doc from org.springframework.core.env.PropertyResolver.resolveRequiredPlaceholders.

Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty. Unresolvable placeholders with no default value will cause an IllegalArgumentException to be thrown.

Returns:String

the resolved String (never null)

Annotations
@Override
Exceptions
IllegalArgumentException:
if given text is null or if any placeholders are unresolvable
setActiveProfilesback to summary
public void setActiveProfiles(String... profiles)

Implements org.springframework.core.env.ConfigurableEnvironment.setActiveProfiles.

Doc from org.springframework.core.env.ConfigurableEnvironment.setActiveProfiles.

Specify the set of profiles active for this Environment. Profiles are evaluated during container bootstrap to determine whether bean definitions should be registered with the container.

Any existing active profiles will be replaced with the given arguments; call with zero arguments to clear the current set of active profiles. Use addActiveProfile to add a profile while preserving the existing set.

Annotations
@Override
setConversionServiceback to summary
public void setConversionService(ConfigurableConversionService conversionService)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setConversionService.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.setConversionService.

Set the ConfigurableConversionService to be used when performing type conversions on properties.

Note

as an alternative to fully replacing the ConversionService, consider adding or removing individual Converter instances by drilling into getConversionService() and calling methods such as #addConverter.

Annotations
@Override
setDefaultProfilesback to summary
public void setDefaultProfiles(String... profiles)

Implements org.springframework.core.env.ConfigurableEnvironment.setDefaultProfiles.

Specify the set of profiles to be made active by default if no other profiles are explicitly made active through setActiveProfiles.

Calling this method removes overrides any reserved default profiles that may have been added during construction of the environment.

Annotations
@Override
See Also
AbstractEnvironment(), getReservedDefaultProfiles()
setIgnoreUnresolvableNestedPlaceholdersback to summary
public void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setIgnoreUnresolvableNestedPlaceholders.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.setIgnoreUnresolvableNestedPlaceholders.

Set whether to throw an exception when encountering an unresolvable placeholder nested within the value of a given property. A false value indicates strict resolution, i.e. that an exception will be thrown. A true value indicates that unresolvable nested placeholders should be passed through in their unresolved ${...} form.

Implementations of getProperty(String) and its variants must inspect the value set here to determine correct behavior when property values contain unresolvable placeholders.

Annotations
@Override
setPlaceholderPrefixback to summary
public void setPlaceholderPrefix(String placeholderPrefix)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderPrefix.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderPrefix.

Set the prefix that placeholders replaced by this resolver must begin with.

Annotations
@Override
setPlaceholderSuffixback to summary
public void setPlaceholderSuffix(String placeholderSuffix)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderSuffix.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.setPlaceholderSuffix.

Set the suffix that placeholders replaced by this resolver must end with.

Annotations
@Override
setRequiredPropertiesback to summary
public void setRequiredProperties(String... requiredProperties)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setRequiredProperties.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.setRequiredProperties.

Specify which properties must be present, to be verified by validateRequiredProperties().

Annotations
@Override
setValueSeparatorback to summary
public void setValueSeparator(String valueSeparator)

Implements org.springframework.core.env.ConfigurablePropertyResolver.setValueSeparator.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.setValueSeparator.

Specify the separating character between the placeholders replaced by this resolver and their associated default value, or null if no such special character should be processed as a value separator.

Annotations
@Override
suppressGetenvAccessback to summary
protected boolean suppressGetenvAccess()

Determine whether to suppress System#getenv()/System#getenv(String) access for the purposes of getSystemEnvironment().

If this method returns true, an empty dummy Map will be used instead of the regular system environment Map, never even trying to call getenv and therefore avoiding security manager warnings (if any).

The default implementation checks for the "spring.getenv.ignore" system property, returning true if its value equals "true" in any case.

See Also
IGNORE_GETENV_PROPERTY_NAME, SpringProperties#getFlag
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
validateProfileback to summary
protected void validateProfile(String profile)

Validate the given profile, called internally prior to adding to the set of active or default profiles.

Subclasses may override to impose further restrictions on profile syntax.

Exceptions
IllegalArgumentException:
if the profile is null, empty, whitespace-only or begins with the profile NOT operator (!).
See Also
acceptsProfiles, addActiveProfile, setDefaultProfiles
validateRequiredPropertiesback to summary
public void validateRequiredProperties() throws MissingRequiredPropertiesException

Implements org.springframework.core.env.ConfigurablePropertyResolver.validateRequiredProperties.

Doc from org.springframework.core.env.ConfigurablePropertyResolver.validateRequiredProperties.

Validate that each of the properties specified by setRequiredProperties is present and resolves to a non-null value.

Annotations
@Override
Exceptions
MissingRequiredPropertiesException:
if any of the required properties are not resolvable.