public interface Environment extends PropertyResolver, LifeCycle<Environment>, ConversionService<Environment>, ResourceLoader
The current application environment. The environment represents the loaded configuration of the application for a current list of active environment names.
The active environment names can be obtained from the getActiveNames()
method and are established from one
of the following sources:
ApplicationContext.run(String...)
methodENVIRONMENTS_PROPERTY
system propertyENVIRONMENTS_ENV
environment variableWhen establishing the environment name from the class the started the application Micronaut will inspect the stacktrace. If JUnit or Spock are
featured in the stacktrace the TEST
environment is included. When running from Android the ANDROID
environment is included.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AMAZON_EC2
Cloud provider amazon ec2.
|
static java.lang.String |
ANDROID
The android environment.
|
static java.lang.String |
AZURE
Cloud provider Microsoft Azure.
|
static java.lang.String |
BARE_METAL
Cloud or non cloud provider on bare metal (unknown).
|
static java.lang.String |
BOOTSTRAP_CONTEXT_PROPERTY
Whether the bootstrap context is enabled.
|
static java.lang.String |
BOOTSTRAP_NAME
The default bootstrap config name.
|
static java.lang.String |
BOOTSTRAP_NAME_PROPERTY
The default bootstrap name.
|
static java.lang.String |
CLI
The cli environment.
|
static java.lang.String |
CLOUD
The cloud environment.
|
static java.lang.String |
CLOUD_FOUNDRY
Running on Cloud Foundry.
|
static java.lang.String |
CLOUD_PLATFORM_PROPERTY
The default bootstrap name.
|
static java.lang.String |
DEDUCE_ENVIRONMENT_ENV
Environment key for whether to deduce environments.
|
static java.lang.String |
DEDUCE_ENVIRONMENT_PROPERTY
Property for whether to deduce environments.
|
static java.lang.String |
DEFAULT_NAME
The default application name.
|
static java.lang.String |
DEVELOPMENT
The development environment.
|
static java.lang.String |
DIGITAL_OCEAN
Cloud provider Digital Ocean.
|
static java.lang.String |
ENVIRONMENTS_ENV
The environment key that stores additional environments.
|
static java.lang.String |
ENVIRONMENTS_PROPERTY
The property that stores additional environments.
|
static java.lang.String |
FUNCTION
The application is executing as a function.
|
static java.lang.String |
GAE
Cloud provider for google app engine.
|
static java.lang.String |
GOOGLE_COMPUTE
Cloud provider google compute instance.
|
static java.lang.String |
HEROKU
Running on Heroku.
|
static java.lang.String |
HOSTNAME
The host name environment variable.
|
static java.lang.String |
IBM
Cloud provider IBM cloud.
|
static java.lang.String |
KUBERNETES
Running on Kubernetes.
|
static java.lang.String |
MICRONAUT
Constant for the the name micronaut.
|
static java.lang.String |
ORACLE_CLOUD
Cloud provider Oracle Cloud.
|
static java.lang.String |
PROPERTY_SOURCES_KEY
The key used to load additional property sources.
|
static java.lang.String |
TEST
The test environment.
|
SHARED
Modifier and Type | Method and Description |
---|---|
Environment |
addConfigurationExcludes(java.lang.String... names)
Exclude configurations by name.
|
Environment |
addConfigurationIncludes(java.lang.String... names)
Exclude configurations by name.
|
default Environment |
addPackage(java.lang.Package pkg)
Add an application package.
|
Environment |
addPackage(java.lang.String pkg)
Add an application package.
|
Environment |
addPropertySource(PropertySource propertySource)
Adds a property source to this environment.
|
default Environment |
addPropertySource(java.lang.String name,
java.util.Map<java.lang.String,? super java.lang.Object> values)
Add a property source for the given map.
|
java.util.Set<java.lang.String> |
getActiveNames()
Should respect the order as provided.
|
default java.lang.ClassLoader |
getClassLoader() |
java.util.Collection<java.lang.String> |
getPackages() |
PropertyPlaceholderResolver |
getPlaceholderResolver() |
java.util.Collection<PropertySourceLoader> |
getPropertySourceLoaders()
Obtains the
PropertySourceLoader instances. |
java.util.Collection<PropertySource> |
getPropertySources() |
boolean |
isActive(BeanConfiguration configuration)
Whether the current environment includes the given configuration.
|
default boolean |
isPresent(java.lang.String className)
Check whether the given class is present within this environment.
|
java.util.Map<java.lang.String,java.lang.Object> |
refreshAndDiff()
Refresh the environment from the list of
PropertySource instances and return a diff of the changes. |
Environment |
removePropertySource(PropertySource propertySource)
Removes a property source from this environment.
|
default java.util.stream.Stream<java.lang.Class> |
scan(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Scan the current environment for classes annotated with the given annotation.
|
default java.util.stream.Stream<java.lang.Class> |
scan(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.String... packages)
Scan the current environment for classes annotated with the given annotation.
|
containsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyEntries, getRequiredProperty, nameOf
get, get, get
close, isRunning, refresh, start, stop
addConverter, addConverter, canConvert, convert, convert, convert, convert, convertRequired, convertRequired
forBase, getResource, getResourceAsStream, getResources, supportsPrefix
static final java.lang.String MICRONAUT
static final java.lang.String TEST
static final java.lang.String DEVELOPMENT
static final java.lang.String ANDROID
static final java.lang.String CLI
static final java.lang.String CLOUD
static final java.lang.String FUNCTION
static final java.lang.String BOOTSTRAP_NAME_PROPERTY
static final java.lang.String BOOTSTRAP_CONTEXT_PROPERTY
static final java.lang.String CLOUD_PLATFORM_PROPERTY
static final java.lang.String ENVIRONMENTS_PROPERTY
static final java.lang.String ENVIRONMENTS_ENV
static final java.lang.String BOOTSTRAP_NAME
static final java.lang.String DEFAULT_NAME
static final java.lang.String GOOGLE_COMPUTE
static final java.lang.String GAE
static final java.lang.String AMAZON_EC2
static final java.lang.String AZURE
static final java.lang.String ORACLE_CLOUD
static final java.lang.String DIGITAL_OCEAN
static final java.lang.String BARE_METAL
static final java.lang.String IBM
static final java.lang.String KUBERNETES
static final java.lang.String CLOUD_FOUNDRY
static final java.lang.String HEROKU
static final java.lang.String PROPERTY_SOURCES_KEY
static final java.lang.String HOSTNAME
static final java.lang.String DEDUCE_ENVIRONMENT_PROPERTY
static final java.lang.String DEDUCE_ENVIRONMENT_ENV
java.util.Set<java.lang.String> getActiveNames()
java.util.Collection<PropertySource> getPropertySources()
Environment addPropertySource(PropertySource propertySource)
propertySource
- The property sourceEnvironment removePropertySource(PropertySource propertySource)
propertySource
- The property sourceEnvironment addPackage(java.lang.String pkg)
pkg
- The package to addEnvironment addConfigurationExcludes(java.lang.String... names)
names
- The names of the configurationEnvironment addConfigurationIncludes(java.lang.String... names)
names
- The names of the configurationjava.util.Collection<java.lang.String> getPackages()
PropertyPlaceholderResolver getPlaceholderResolver()
java.util.Map<java.lang.String,java.lang.Object> refreshAndDiff()
PropertySource
instances and return a diff of the changes.default Environment addPropertySource(java.lang.String name, @Nullable java.util.Map<java.lang.String,? super java.lang.Object> values)
name
- The namevalues
- The valuesdefault Environment addPackage(java.lang.Package pkg)
pkg
- The package to adddefault java.util.stream.Stream<java.lang.Class> scan(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
annotation
- The annotation to scandefault java.util.stream.Stream<java.lang.Class> scan(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.String... packages)
annotation
- The annotation to scanpackages
- The packages to scandefault java.lang.ClassLoader getClassLoader()
default boolean isPresent(java.lang.String className)
className
- The class nameboolean isActive(BeanConfiguration configuration)
configuration
- The configurationjava.util.Collection<PropertySourceLoader> getPropertySourceLoaders()
PropertySourceLoader
instances.PropertySourceLoader