public abstract class

AbstractEnvironment

extends Object
implements ConfigurableEnvironment
java.lang.Object
   ↳ org.springframework.core.env.AbstractEnvironment
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Abstract base class for Environment implementations.

Summary

Constants
String ACTIVE_PROFILES_PROPERTY_NAME Name of property to set to specify active profiles: {@value }.
String DEFAULT_PROFILES_PROPERTY_NAME Name of property to set to specify default profiles: {@value }.
Fields
protected final Log logger
Public Constructors
AbstractEnvironment()
Public Methods
boolean acceptsProfiles(String... profiles)
boolean containsProperty(String key)
Return whether the given property key is available for resolution.
String[] getActiveProfiles()
Return the set of profiles explicitly made active for this environment.
ConversionService getConversionService()
String[] getDefaultProfiles()
Return the set of profiles to be active by default when no active profiles have been set explicitly.
<T> T getProperty(String key, Class<T> targetType)
Return the property value associated with the given key, or null if the key cannot be resolved.
String getProperty(String key)
Return the property value associated with the given key.
ConfigurablePropertyResolver getPropertyResolver()
MutablePropertySources getPropertySources()
Return the PropertySources for this environment in mutable form
String getRequiredProperty(String key)
Return the property value associated with the given key, converted to the given targetType (never null).
<T> T getRequiredProperty(String key, Class<T> targetType)
Return the property value associated with the given key, converted to the given targetType (never null).
Map<StringObject> getSystemEnvironment()
Return the value of getenv() if allowed by the current SecurityManager, otherwise return a map implementation that will attempt to access individual keys using calls to getenv(String).
Map<StringObject> getSystemProperties()
Return the value of getProperties() if allowed by the current SecurityManager, otherwise return a map implementation that will attempt to access individual keys using calls to getProperty(String).
String resolvePlaceholders(String text)
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty(String).
String resolveRequiredPlaceholders(String text)
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty(String).
void setActiveProfiles(String... profiles)
Specify the set of profiles active for this Environment.
void setConversionService(ConversionService conversionService)
Set the ConversionService to be used when performing type conversions on properties.
void setDefaultProfiles(String... profiles)
Specify the set of profiles to be made active by default if no other profiles are explicitly made active through setActiveProfiles(String...).
void setPlaceholderPrefix(String placeholderPrefix)
void setPlaceholderSuffix(String placeholderSuffix)
void setValueSeparator(String valueSeparator)
String toString()
Protected Methods
Set<String> doGetActiveProfiles()
Set<String> doGetDefaultProfiles()
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.core.env.ConfigurableEnvironment
From interface org.springframework.core.env.ConfigurablePropertyResolver
From interface org.springframework.core.env.Environment
From interface org.springframework.core.env.PropertyResolver

Constants

public static final String ACTIVE_PROFILES_PROPERTY_NAME

Also: SpringCore

Name of property to set to specify active profiles: {@value }. May be comma delimited.

Constant Value: "spring.profiles.active"

public static final String DEFAULT_PROFILES_PROPERTY_NAME

Also: SpringCore

Name of property to set to specify default profiles: {@value }. May be comma delimited.

Constant Value: "spring.profiles.default"

Fields

protected final Log logger

Also: SpringCore

Public Constructors

public AbstractEnvironment ()

Also: SpringCore

Public Methods

public boolean acceptsProfiles (String... profiles)

Also: SpringCore

public boolean containsProperty (String key)

Also: SpringCore

Return whether the given property key is available for resolution.

public String[] getActiveProfiles ()

Also: SpringCore

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, often based on deployment environment. Profiles can be activated by setting "spring.profiles.active" as a system property or by calling setActiveProfiles(String).

If no profiles have explicitly been specified as active, then any 'default' profiles will implicitly be considered active.

public ConversionService getConversionService ()

Also: SpringCore

public String[] getDefaultProfiles ()

Also: SpringCore

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

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

Also: SpringCore

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

public String getProperty (String key)

Also: SpringCore

Return the property value associated with the given key.

public ConfigurablePropertyResolver getPropertyResolver ()

Also: SpringCore

public MutablePropertySources getPropertySources ()

Also: SpringCore

Return the PropertySources for this environment in mutable form

public String getRequiredProperty (String key)

Also: SpringCore

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

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

Also: SpringCore

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

public Map<StringObject> getSystemEnvironment ()

Also: SpringCore

Return the value of getenv() if allowed by the current SecurityManager, otherwise return a map implementation that will attempt to access individual keys using calls to getenv(String).

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.

Calls to get(Object) on the Map returned will never throw IllegalAccessException; in cases where the SecurityManager forbids access to a property, null will be returned and an INFO-level log message will be issued noting the exception.

public Map<StringObject> getSystemProperties ()

Also: SpringCore

Return the value of getProperties() if allowed by the current SecurityManager, otherwise return a map implementation that will attempt to access individual keys using calls to getProperty(String).

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.

Calls to get(Object) on the Map returned will never throw IllegalAccessException; in cases where the SecurityManager forbids access to a property, null will be returned and an INFO-level log message will be issued noting the exception.

public String resolvePlaceholders (String text)

Also: SpringCore

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

Parameters
text the String to resolve
Returns
  • the resolved String (never null)

public String resolveRequiredPlaceholders (String text)

Also: SpringCore

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

Returns
  • the resolved String (never null)

public void setActiveProfiles (String... profiles)

Also: SpringCore

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.

public void setConversionService (ConversionService conversionService)

Also: SpringCore

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

public void setDefaultProfiles (String... profiles)

Also: SpringCore

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

public void setPlaceholderPrefix (String placeholderPrefix)

Also: SpringCore

public void setPlaceholderSuffix (String placeholderSuffix)

Also: SpringCore

public void setValueSeparator (String valueSeparator)

Also: SpringCore

public String toString ()

Protected Methods

protected Set<String> doGetActiveProfiles ()

Also: SpringCore

protected Set<String> doGetDefaultProfiles ()

Also: SpringCore