|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.core.env.AbstractEnvironment
org.springframework.core.env.DefaultEnvironment
public class DefaultEnvironment
Default implementation of the Environment interface. Used throughout all non-Web*
ApplicationContext implementations.
In addition to the usual functions of a ConfigurableEnvironment such as property
resolution and profile-related operations, this implementation configures two default property
sources, to be searched in the following order:
environment.getPropertyResolver().getProperty("xyz").
This ordering is chosen by default because system properties are per-JVM, while environment
variables may be the same across many JVMs on a given system. Giving system properties
precedence allows for overriding of environment variables on a per-JVM basis.
These default property sources may be removed, reordered, or replaced; and additional
property sources may be added using the MutablePropertySources instance available
from AbstractEnvironment.getPropertySources().
ConfigurableEnvironment environment = new DefaultEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); MapmyMap = new HashMap (); myMap.put("xyz", "myValue"); propertySources.addFirst(new MapPropertySource("MY_MAP", myMap));
MutablePropertySources propertySources = environment.getPropertySources(); propertySources.remove(DefaultEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)
MutablePropertySources propertySources = environment.getPropertySources();
MockPropertySource mockEnvVars = new MockPropertySource().withProperty("xyz", "myValue");
propertySources.replace(DefaultEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, mockEnvVars);
When an Environment is being used by an ApplicationContext, it is important
that any such PropertySource manipulations be performed before the context's refresh() method is
called. This ensures that all PropertySources are available during the container bootstrap process,
including use by property placeholder configurers.
ConfigurableEnvironment,
DefaultWebEnvironment| Field Summary | |
|---|---|
static String |
SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME
System environment property source name: "systemEnvironment" |
static String |
SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME
JVM system properties property source name: "systemProperties" |
| Fields inherited from class org.springframework.core.env.AbstractEnvironment |
|---|
ACTIVE_PROFILES_PROPERTY_NAME, DEFAULT_PROFILES_PROPERTY_NAME, logger |
| Constructor Summary | |
|---|---|
DefaultEnvironment()
Create a new Environment populated with property sources in the following order:
"systemProperties"
"systemEnvironment"
|
|
| Method Summary |
|---|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME
public static final String SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME
| Constructor Detail |
|---|
public DefaultEnvironment()
Environment populated with property sources in the following order:
Properties present in "systemProperties" will take precedence over those in "systemEnvironment".
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||