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 String |
AMAZON_EC2
Cloud provider amazon ec2.
|
static String |
ANDROID
The android environment.
|
static String |
AZURE
Cloud provider Microsoft Azure.
|
static String |
BARE_METAL
Cloud or non cloud provider on bare metal (unknown).
|
static String |
BOOTSTRAP_CONTEXT_PROPERTY
Whether the bootstrap context is enabled.
|
static String |
BOOTSTRAP_NAME
The default bootstrap config name.
|
static String |
BOOTSTRAP_NAME_PROPERTY
The default bootstrap name.
|
static String |
CLI
The cli environment.
|
static String |
CLOUD
The cloud environment.
|
static String |
CLOUD_FOUNDRY
Running on Cloud Foundry.
|
static String |
CLOUD_PLATFORM_PROPERTY
The default bootstrap name.
|
static String |
DEDUCE_ENVIRONMENT_ENV
Environment key for whether to deduce environments.
|
static String |
DEDUCE_ENVIRONMENT_PROPERTY
Property for whether to deduce environments.
|
static String |
DEFAULT_NAME
The default application name.
|
static String |
DEVELOPMENT
The development environment.
|
static String |
DIGITAL_OCEAN
Cloud provider Digital Ocean.
|
static String |
ENVIRONMENTS_ENV
The environment key that stores additional environments.
|
static String |
ENVIRONMENTS_PROPERTY
The property that stores additional environments.
|
static String |
FUNCTION
The application is executing as a function.
|
static String |
GAE
Cloud provider for google app engine.
|
static String |
GOOGLE_COMPUTE
Cloud provider google compute instance.
|
static String |
HEROKU
Running on Heroku.
|
static String |
HOSTNAME
The host name environment variable.
|
static String |
IBM
Cloud provider IBM cloud.
|
static String |
KUBERNETES
Running on Kubernetes.
|
static String |
MICRONAUT
Constant for the the name micronaut.
|
static String |
PROPERTY_SOURCES_KEY
The key used to load additional property sources.
|
static String |
TEST
The test environment.
|
SHARED
Modifier and Type | Method and Description |
---|---|
Environment |
addConfigurationExcludes(String... names)
Exclude configurations by name.
|
Environment |
addConfigurationIncludes(String... names)
Exclude configurations by name.
|
default Environment |
addPackage(Package pkg)
Add an application package.
|
Environment |
addPackage(String pkg)
Add an application package.
|
Environment |
addPropertySource(PropertySource propertySource)
Adds a property source to this environment.
|
default Environment |
addPropertySource(String name,
Map<String,? super Object> values)
Add a property source for the given map.
|
Set<String> |
getActiveNames()
Should respect the order as provided.
|
default ClassLoader |
getClassLoader() |
Collection<String> |
getPackages() |
PropertyPlaceholderResolver |
getPlaceholderResolver() |
Collection<PropertySourceLoader> |
getPropertySourceLoaders()
Obtains the
PropertySourceLoader instances. |
Collection<PropertySource> |
getPropertySources() |
boolean |
isActive(BeanConfiguration configuration)
Whether the current environment includes the given configuration.
|
default boolean |
isPresent(String className)
Check whether the given class is present within this environment.
|
Map<String,Object> |
refreshAndDiff()
Refresh the environment from the list of
PropertySource instances and return a diff of the changes. |
default Stream<Class> |
scan(Class<? extends Annotation> annotation)
Scan the current environment for classes annotated with the given annotation.
|
default Stream<Class> |
scan(Class<? extends Annotation> annotation,
String... packages)
Scan the current environment for classes annotated with the given annotation.
|
containsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, 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 String MICRONAUT
static final String TEST
static final String DEVELOPMENT
static final String ANDROID
static final String CLI
static final String CLOUD
static final String FUNCTION
static final String BOOTSTRAP_NAME_PROPERTY
static final String BOOTSTRAP_CONTEXT_PROPERTY
static final String CLOUD_PLATFORM_PROPERTY
static final String ENVIRONMENTS_PROPERTY
static final String ENVIRONMENTS_ENV
static final String BOOTSTRAP_NAME
static final String DEFAULT_NAME
static final String GOOGLE_COMPUTE
static final String GAE
static final String AMAZON_EC2
static final String AZURE
static final String DIGITAL_OCEAN
static final String BARE_METAL
static final String IBM
static final String KUBERNETES
static final String CLOUD_FOUNDRY
static final String HEROKU
static final String PROPERTY_SOURCES_KEY
static final String HOSTNAME
static final String DEDUCE_ENVIRONMENT_PROPERTY
static final String DEDUCE_ENVIRONMENT_ENV
Set<String> getActiveNames()
Collection<PropertySource> getPropertySources()
Environment addPropertySource(PropertySource propertySource)
propertySource
- The property sourceEnvironment addPackage(String pkg)
pkg
- The package to addEnvironment addConfigurationExcludes(String... names)
names
- The names of the configurationEnvironment addConfigurationIncludes(String... names)
names
- The names of the configurationCollection<String> getPackages()
PropertyPlaceholderResolver getPlaceholderResolver()
Map<String,Object> refreshAndDiff()
PropertySource
instances and return a diff of the changes.default Environment addPropertySource(String name, @Nullable Map<String,? super Object> values)
name
- The namevalues
- The valuesdefault Environment addPackage(Package pkg)
pkg
- The package to adddefault Stream<Class> scan(Class<? extends Annotation> annotation)
annotation
- The annotation to scandefault Stream<Class> scan(Class<? extends Annotation> annotation, String... packages)
annotation
- The annotation to scanpackages
- The packages to scandefault ClassLoader getClassLoader()
default boolean isPresent(String className)
className
- The class nameboolean isActive(BeanConfiguration configuration)
configuration
- The configurationCollection<PropertySourceLoader> getPropertySourceLoaders()
PropertySourceLoader
instances.PropertySourceLoader