public interface Environment extends PropertyResolver
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
@Profile annotation for
syntax details. The role of the
Environment object with relation to profiles is
in determining which profiles (if any) are currently active, and which profiles (if any) should be active
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
ApplicationContext may register to be
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
Environment directly but instead may have to have
values replaced by a property placeholder configurer such as
PropertySourcesPlaceholderConfigurer, which itself is
as of Spring 3.1 is registered by default when using
Configuration of the environment object must be done through the
ConfigurableEnvironment interface, returned from all
getEnvironment() methods. See
ConfigurableEnvironment Javadoc for usage examples demonstrating manipulation
of property sources prior to application context
|Modifier and Type||Method and Description|
Return 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.
Return the set of profiles explicitly made active for this environment.
Return the set of profiles to be active by default when no active profiles have been set explicitly.
If no profiles have explicitly been specified as active, then any default profiles will automatically be activated.
boolean acceptsProfiles(java.lang.String... profiles)
env.acceptsProfiles("p1", "!p2")will return
trueif profile 'p1' is active or 'p2' is not active.