Interface Environment
- All Superinterfaces:
AutoCloseable, Closeable, ConversionServiceProvider, LifeCycle<Environment>, PropertyResolver, ResourceLoader, ValueResolver<String>
public interface Environment
extends PropertyResolver, LifeCycle<Environment>, ResourceLoader, ConversionServiceProvider
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. -
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 EnvironmentaddPropertySource(String name, @Nullable Map<String, ? super Object> values) Deprecated, for removal: This API element is subject to removal in a future version.static Environmentcreate(ApplicationContextConfiguration configuration) Creates and returns a new instance ofEnvironmentusing the provided application context configuration.Should respect the order as provided.default ClassLoaderRetrieves the conversion service instance associated with the environment.default Optional<PropertyEntry> getPropertyEntry(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 PropertyResolver
containsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyEntries, getPropertyEntries, getPropertyPathMatches, getRequiredPropertyMethods inherited from interface ResourceLoader
forBase, getResource, getResourceAsStream, getResources, supportsPrefixMethods inherited from interface ValueResolver
get, get, get
-
Field Details
-
MICRONAUT
-
TEST
-
DEVELOPMENT
-
ANDROID
-
CLI
-
CLOUD
-
FUNCTION
-
BOOTSTRAP_NAME_PROPERTY
System property to override the default bootstrap name.- See Also:
-
BOOTSTRAP_CONTEXT_PROPERTY
-
CLOUD_PLATFORM_PROPERTY
-
ENVIRONMENTS_PROPERTY
The property that stores additional environments.- See Also:
-
ENVIRONMENTS_ENV
The environment key that stores additional environments.- See Also:
-
BOOTSTRAP_NAME
-
DEFAULT_NAME
-
GOOGLE_COMPUTE
-
GAE
-
AMAZON_EC2
-
AZURE
-
ORACLE_CLOUD
-
DIGITAL_OCEAN
-
BARE_METAL
-
IBM
-
KUBERNETES
-
CLOUD_FOUNDRY
-
HEROKU
-
PROPERTY_SOURCES_KEY
The key used to load additional property sources.- See Also:
-
HOSTNAME
-
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
-
create
Creates and returns a new instance ofEnvironmentusing the provided application context configuration.- Parameters:
configuration- the application context configuration, must not be null- Returns:
- a new instance of
Environment, never null - Since:
- 5.0
-
getActiveNames
-
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 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
-
getConversionService
MutableConversionService getConversionService()Retrieves the conversion service instance associated with the environment.- Specified by:
getConversionServicein interfaceConversionServiceProvider- Returns:
- A
ConversionServicethat allows adding new type converters. - Since:
- 5.0
-
addPropertySource(PropertySource)