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_PROPERTYsystem property - The value of the
ENVIRONMENTS_ENVenvironment 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
FieldsModifier and TypeFieldDescriptionstatic final StringCloud provider amazon ec2.static final StringThe android environment.static final StringCloud provider Microsoft Azure.static final StringCloud or non cloud provider on bare metal (unknown).static final StringWhether the bootstrap context is enabled.static final StringThe default bootstrap config name.static final StringSystem property to override the default bootstrap name.static final StringThe cli environment.static final StringThe cloud environment.static final StringRunning on Cloud Foundry.static final StringThe default bootstrap name.static final StringEnvironment key for whether to deduce cloud environments.static final StringProperty for whether to deduce cloud environments.static final StringEnvironment key for whether to deduce environments.static final StringProperty for whether to deduce environments.static final StringThe default application name.static final StringThe development environment.static final StringCloud provider Digital Ocean.static final StringThe environment key that stores additional environments.static final StringThe property that stores additional environments.static final StringThe application is executing as a function.static final StringCloud provider for google app engine.static final StringCloud provider google compute instance.static final StringRunning on Heroku.static final StringThe host name environment variable.static final StringCloud provider IBM cloud.static final StringRunning on Kubernetes.static final StringConstant for the name micronaut.static final StringCloud provider Oracle Cloud.static final StringThe key used to load additional property sources.static final StringThe 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 EnvironmentaddPackage(Package pkg) Add an application package.addPackage(String pkg) Add an application package.addPropertySource(PropertySource propertySource) Adds a property source to this environment.default EnvironmentDeprecated, for removal: This API element is subject to removal in a future version.Should respect the order as provided.default ClassLoaderdefault Optional<PropertyEntry>getPropertyEntry(@NonNull String name) Resolve information about a property.Obtains thePropertySourceLoaderinstances.booleanisActive(BeanConfiguration configuration) Whether the current environment includes the given configuration.default booleanCheck whether the given class is present within this environment.Refresh the environment from the list ofPropertySourceinstances 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, convertRequiredMethods inherited from interface io.micronaut.context.LifeCycle
close, isRunning, refresh, start, stopMethods inherited from interface io.micronaut.core.convert.MutableConversionService
addConverter, addConverterMethods inherited from interface io.micronaut.core.value.PropertyResolver
containsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyEntries, getPropertyEntries, getPropertyPathMatches, getRequiredPropertyMethods inherited from interface io.micronaut.core.io.ResourceLoader
forBase, getResource, getResourceAsStream, getResources, supportsPrefixMethods 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 ofPropertySourceinstances and return a diff of the changes.- Returns:
- The values that changed
-
addPropertySource
@Deprecated(forRemoval=true, since="4.8.0") default Environment addPropertySource(String name, @Nullable @Nullable Map<String, ? super Object> values) Deprecated, for removal: This API element is subject to removal in a future version.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 thePropertySourceLoaderinstances.- Returns:
- A collection of
PropertySourceLoader
-
getPropertyEntry
Resolve information about a property.- Parameters:
name- The property name- Returns:
- The entry.
- Since:
- 4.8.0
-
addPropertySource(PropertySource)