接口 Environment
- 所有超级接口:
PropertyResolver
- 所有已知子接口:
ConfigurableEnvironment
- 所有已知实现类:
AbstractEnvironment,StandardEnvironment
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 or the
@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
by 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 ApplicationContext may register to be EnvironmentAware or @Inject the
Environment in order to query profile state or resolve properties directly.
Configuration of the environment object must be done through the
ConfigurableEnvironment interface, returned from all
AbstractApplicationContext subclass getEnvironment() methods. See
ConfigurableEnvironment Javadoc for usage examples demonstrating manipulation
of property sources prior to application context refresh().
- 从以下版本开始:
- 4.0
- 作者:
- Chris Beams, Harry Yang
- 另请参阅:
-
PropertyResolverEnvironmentCapableConfigurableEnvironmentAbstractEnvironmentStandardEnvironmentcn.taketoday.context.EnvironmentAwarecn.taketoday.context.ConfigurableApplicationContext#getEnvironmentcn.taketoday.context.ConfigurableApplicationContext#setEnvironmentcn.taketoday.context.support.AbstractApplicationContext#createEnvironment
-
字段概要
字段修饰符和类型字段说明static final StringName of reserved default profile name: "default".static final StringName of theEnvironmentbean in the factory.static final StringName of property to set to specify active profiles: "infra.profiles.active".static final StringName of property to set to specify profiles active by default: "infra.profiles.default".static final StringSystem property that instructs to ignore system environment variables, i.e. to never attempt to retrieve such a variable viaSystem.getenv().static final StringName of the System environment bean in the factory.static final StringName of the System properties bean in the factory. -
方法概要
修饰符和类型方法说明booleanacceptsProfiles(Profiles profiles) Determine whether the givenProfilespredicate matches the active profiles — or in the case of no explicit active profiles, whether the givenProfilespredicate matches the default profiles.String[]Return the set of profiles explicitly made active for this environment.String[]Return the set of profiles to be active by default when no active profiles have been set explicitly.default booleanmatchesProfiles(String... profileExpressions) Determine whether one of the given profile expressions matches the active profiles — or in the case of no explicit active profiles, whether one of the given profile expressions matches the default profiles.从接口继承的方法 cn.taketoday.core.env.PropertyResolver
containsProperty, getFlag, getFlag, getProperty, getProperty, getProperty, getProperty, getRequiredProperty, getRequiredProperty, resolvePlaceholders, resolveRequiredPlaceholders
-
字段详细资料
-
ENVIRONMENT_BEAN_NAME
Name of theEnvironmentbean in the factory.- 从以下版本开始:
- 4.0
- 另请参阅:
-
SYSTEM_PROPERTIES_BEAN_NAME
Name of the System properties bean in the factory.- 从以下版本开始:
- 4.0
- 另请参阅:
-
SYSTEM_ENVIRONMENT_BEAN_NAME
Name of the System environment bean in the factory.- 从以下版本开始:
- 4.0
- 另请参阅:
-
KEY_IGNORE_GETENV
System property that instructs to ignore system environment variables, i.e. to never attempt to retrieve such a variable viaSystem.getenv().The default is "false", falling back to system environment variable checks if an 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
getenvcalls coming from TODAY. -
KEY_ACTIVE_PROFILES
Name of property to set to specify active profiles: "infra.profiles.active". 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
SystemEnvironmentPropertySourceis in use, this property may be specified as an environment variable asCONTEXT_PROFILES_ACTIVE. -
KEY_DEFAULT_PROFILES
Name of property to set to specify profiles active by default: "infra.profiles.default". 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
SystemEnvironmentPropertySourceis in use, this property may be specified as an environment variable asCONTEXT_PROFILES_DEFAULT. -
DEFAULT_PROFILE
Name of reserved default profile name: "default". If no default profile names are explicitly and no active profile names are explicitly set, this profile will automatically be activated by default.
-
-
方法详细资料
-
getActiveProfiles
String[] 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 "infra.profiles.active" as a system property or by callingConfigurableEnvironment.setActiveProfiles(String...).If no profiles have explicitly been specified as active, then any default profiles will automatically be activated.
-
getDefaultProfiles
String[] getDefaultProfiles()Return the set of profiles to be active by default when no active profiles have been set explicitly. -
matchesProfiles
Determine whether one of the given profile expressions matches the active profiles — or in the case of no explicit active profiles, whether one of the given profile expressions matches the default profiles.Profile expressions allow for complex, boolean profile logic to be expressed — for example
"p1 & p2","(p1 & p2) | p3", etc. SeeProfiles.of(String...)for details on the supported expression syntax.This method is a convenient shortcut for
env.acceptsProfiles(Profiles.of(profileExpressions)). -
acceptsProfiles
Determine whether the givenProfilespredicate matches the active profiles — or in the case of no explicit active profiles, whether the givenProfilespredicate matches the default profiles.If you wish provide profile expressions directly as strings, use
matchesProfiles(String...)instead.
-