Package io.micronaut.context.env
Interface Environment
- All Superinterfaces:
AutoCloseable
,Closeable
,ConversionService
,LifeCycle<Environment>
,MutableConversionService
,PropertyResolver
,ResourceLoader
,ValueResolver<String>
- All Known Implementing Classes:
DefaultEnvironment
public interface Environment
extends PropertyResolver, LifeCycle<Environment>, MutableConversionService, 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:
- Environment names passed to the
ApplicationContext.run(String...)
method - The value of the
ENVIRONMENTS_PROPERTY
system property - The value of the
ENVIRONMENTS_ENV
environment variable - The class that started the application
When 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.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Cloud provider amazon ec2.static final String
The android environment.static final String
Cloud provider Microsoft Azure.static final String
Cloud or non cloud provider on bare metal (unknown).static final String
Whether the bootstrap context is enabled.static final String
The default bootstrap config name.static final String
System property to override the default bootstrap name.static final String
The cli environment.static final String
The cloud environment.static final String
Running on Cloud Foundry.static final String
The default bootstrap name.static final String
Environment key for whether to deduce cloud environments.static final String
Property for whether to deduce cloud environments.static final String
Environment key for whether to deduce environments.static final String
Property for whether to deduce environments.static final String
The default application name.static final String
The development environment.static final String
Cloud provider Digital Ocean.static final String
The environment key that stores additional environments.static final String
The property that stores additional environments.static final String
The application is executing as a function.static final String
Cloud provider for google app engine.static final String
Cloud provider google compute instance.static final String
Running on Heroku.static final String
The host name environment variable.static final String
Cloud provider IBM cloud.static final String
Running on Kubernetes.static final String
Constant for the name micronaut.static final String
Cloud provider Oracle Cloud.static final String
The key used to load additional property sources.static final String
The test environment.Fields inherited from interface io.micronaut.core.convert.ConversionService
SHARED
-
Method Summary
Modifier and TypeMethodDescriptionaddConfigurationExcludes
(String... names) Exclude configurations by name.addConfigurationIncludes
(String... names) Exclude configurations by name.default Environment
addPackage
(Package pkg) Add an application package.addPackage
(String pkg) Add an application package.addPropertySource
(PropertySource propertySource) Adds a property source to this environment.default Environment
Add a property source for the given map.Should respect the order as provided.default ClassLoader
Obtains thePropertySourceLoader
instances.boolean
isActive
(BeanConfiguration configuration) Whether the current environment includes the given configuration.default boolean
Check whether the given class is present within this environment.Refresh the environment from the list ofPropertySource
instances and return a diff of the changes.removePropertySource
(PropertySource propertySource) Removes a property source from this environment.scan
(Class<? extends Annotation> annotation) Scan the current environment for classes annotated with the given annotation.scan
(Class<? extends Annotation> annotation, String... packages) Scan the current environment for classes annotated with the given annotation.Methods inherited from interface io.micronaut.core.convert.ConversionService
canConvert, convert, convert, convert, convert, convert, convert, convertRequired, convertRequired, convertRequired
Methods inherited from interface io.micronaut.context.LifeCycle
close, isRunning, refresh, start, stop
Methods inherited from interface io.micronaut.core.convert.MutableConversionService
addConverter, addConverter
Methods inherited from interface io.micronaut.core.value.PropertyResolver
containsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyEntries, getPropertyEntries, getPropertyPathMatches, getRequiredProperty
Methods inherited from interface io.micronaut.core.io.ResourceLoader
forBase, getResource, getResourceAsStream, getResources, supportsPrefix
Methods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get
-
Field Details
-
MICRONAUT
Constant for the name micronaut.- See Also:
-
TEST
The test environment.- See Also:
-
DEVELOPMENT
The development environment.- See Also:
-
ANDROID
The android environment.- See Also:
-
CLI
The cli environment.- See Also:
-
CLOUD
The cloud environment.- See Also:
-
FUNCTION
The application is executing as a function.- See Also:
-
BOOTSTRAP_NAME_PROPERTY
System property to override the default bootstrap name.- See Also:
-
BOOTSTRAP_CONTEXT_PROPERTY
Whether the bootstrap context is enabled.- See Also:
-
CLOUD_PLATFORM_PROPERTY
The default bootstrap name.- See Also:
-
ENVIRONMENTS_PROPERTY
The property that stores additional environments.- See Also:
-
ENVIRONMENTS_ENV
The environment key that stores additional environments.- See Also:
-
BOOTSTRAP_NAME
The default bootstrap config name.- See Also:
-
DEFAULT_NAME
The default application name.- See Also:
-
GOOGLE_COMPUTE
Cloud provider google compute instance.- See Also:
-
GAE
Cloud provider for google app engine.- See Also:
-
AMAZON_EC2
Cloud provider amazon ec2.- See Also:
-
AZURE
Cloud provider Microsoft Azure.- See Also:
-
ORACLE_CLOUD
Cloud provider Oracle Cloud.- See Also:
-
DIGITAL_OCEAN
Cloud provider Digital Ocean.- See Also:
-
BARE_METAL
Cloud or non cloud provider on bare metal (unknown).- See Also:
-
IBM
Cloud provider IBM cloud.- See Also:
-
KUBERNETES
Running on Kubernetes.- See Also:
-
CLOUD_FOUNDRY
Running on Cloud Foundry.- See Also:
-
HEROKU
Running on Heroku.- See Also:
-
PROPERTY_SOURCES_KEY
The key used to load additional property sources.- See Also:
-
HOSTNAME
The host name environment variable.- See Also:
-
DEDUCE_ENVIRONMENT_PROPERTY
Property for whether to deduce environments.- See Also:
-
DEDUCE_ENVIRONMENT_ENV
Environment key for whether to deduce environments.- See Also:
-
DEDUCE_CLOUD_ENVIRONMENT_PROPERTY
Property for whether to deduce cloud environments.- See Also:
-
DEDUCE_CLOUD_ENVIRONMENT_ENV
Environment key for whether to deduce cloud environments.- See Also:
-
-
Method Details
-
getActiveNames
Should respect the order as provided.- Returns:
- The active environment names
-
getPropertySources
Collection<PropertySource> getPropertySources()- Returns:
- The active property sources
-
addPropertySource
Adds a property source to this environment.- Parameters:
propertySource
- The property source- Returns:
- This environment
-
removePropertySource
Removes a property source from this environment.- Parameters:
propertySource
- The property source- Returns:
- This environment
-
addPackage
Add an application package. Application packages are candidates for scanning for tools that need it (such as JPA).- Parameters:
pkg
- The package to add- Returns:
- This environment
-
addConfigurationExcludes
Exclude configurations by name.- Parameters:
names
- The names of the configuration- Returns:
- This environment
-
addConfigurationIncludes
Exclude configurations by name.- Parameters:
names
- The names of the configuration- Returns:
- This environment
-
getPackages
Collection<String> getPackages()- Returns:
- The application packages
-
getPlaceholderResolver
PropertyPlaceholderResolver getPlaceholderResolver()- Returns:
- The placeholder resolver
-
refreshAndDiff
Refresh the environment from the list ofPropertySource
instances and return a diff of the changes.- Returns:
- The values that changed
-
addPropertySource
default Environment addPropertySource(String name, @Nullable @Nullable Map<String, ? super Object> values) Add a property source for the given map.- Parameters:
name
- The namevalues
- The values- Returns:
- This environment
-
addPackage
Add an application package. Application packages are candidates for scanning for tools that need it (such as JPA).- Parameters:
pkg
- The package to add- Returns:
- This environment
-
scan
Scan the current environment for classes annotated with the given annotation. Use with care, repeated invocations should be avoided for performance reasons.- Parameters:
annotation
- The annotation to scan- Returns:
- The classes
-
scan
Scan the current environment for classes annotated with the given annotation. Use with care, repeated invocations should be avoided for performance reasons.- Parameters:
annotation
- The annotation to scanpackages
- The packages to scan- Returns:
- The classes
-
getClassLoader
- Returns:
- The class loader for the environment
-
isPresent
Check whether the given class is present within this environment.- Parameters:
className
- The class name- Returns:
- True if it is
-
isActive
Whether the current environment includes the given configuration.- Parameters:
configuration
- The configuration- Returns:
- True if it does
-
getPropertySourceLoaders
Collection<PropertySourceLoader> getPropertySourceLoaders()Obtains thePropertySourceLoader
instances.- Returns:
- A collection of
PropertySourceLoader
-