Interface representing the environment in which the current application is running. Models two key aspects of the application environment:
profiles and
properties. Methods related to property access are exposed via the {@link PropertyResolver} superinterface.
A profile is a named, logical group of bean definitions to be registered with the container only if the given profile is active. Beans may be assigned to a profile whether defined in XML or via annotations; see the spring-beans 3.1 schema or the {@link org.springframework.context.annotation.Profile @Profile} annotation forsyntax details. The role of the {@code Environment} object with relation to profiles isin determining which profiles (if any) are currently {@linkplain #getActiveProfiles active}, and which profiles (if any) should be {@linkplain #getDefaultProfiles activeby default}.
Properties play an important role in almost all applications, and may originate from a variety of sources: properties files, JVM system properties, system environment variables, JNDI, servlet context parameters, ad-hoc Properties objects, Maps, and so on. The role of the environment object with relation to properties is to provide the user with a convenient service interface for configuring property sources and resolving properties from them.
Beans managed within an {@code ApplicationContext} may register to be {@link org.springframework.context.EnvironmentAware EnvironmentAware} or {@code @Inject} the{@code Environment} in order to query profile state or resolve properties directly.
In most cases, however, application-level beans should not need to interact with the {@code Environment} directly but instead may have to have ${...}
propertyvalues replaced by a property placeholder configurer such as {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer PropertySourcesPlaceholderConfigurer}, which itself is {@code EnvironmentAware} andas of Spring 3.1 is registered by default when using {@code }.
Configuration of the environment object must be done through the {@code ConfigurableEnvironment} interface, returned from all{@code AbstractApplicationContext} subclass {@code getEnvironment()} methods. See{@link ConfigurableEnvironment} Javadoc for usage examples demonstrating manipulationof property sources prior to application context {@code refresh()}.
@author Chris Beams
@since 3.1
@see PropertyResolver
@see EnvironmentCapable
@see ConfigurableEnvironment
@see AbstractEnvironment
@see StandardEnvironment
@see org.springframework.context.EnvironmentAware
@see org.springframework.context.ConfigurableApplicationContext#getEnvironment
@see org.springframework.context.ConfigurableApplicationContext#setEnvironment
@see org.springframework.context.support.AbstractApplicationContext#createEnvironment