Package io.micronaut.context.env
Interface Environment
-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable,io.micronaut.core.convert.ConversionService<Environment>,LifeCycle<Environment>,io.micronaut.core.value.PropertyResolver,io.micronaut.core.io.ResourceLoader,io.micronaut.core.value.ValueResolver<java.lang.String>
- All Known Implementing Classes:
DefaultEnvironment
public interface Environment extends io.micronaut.core.value.PropertyResolver, LifeCycle<Environment>, io.micronaut.core.convert.ConversionService<Environment>, io.micronaut.core.io.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
TESTenvironment is included. When running from Android theANDROIDenvironment is included.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAMAZON_EC2Cloud provider amazon ec2.static java.lang.StringANDROIDThe android environment.static java.lang.StringAZURECloud provider Microsoft Azure.static java.lang.StringBARE_METALCloud or non cloud provider on bare metal (unknown).static java.lang.StringBOOTSTRAP_CONTEXT_PROPERTYWhether the bootstrap context is enabled.static java.lang.StringBOOTSTRAP_NAMEThe default bootstrap config name.static java.lang.StringBOOTSTRAP_NAME_PROPERTYSystem property to override the default bootstrap name.static java.lang.StringCLIThe cli environment.static java.lang.StringCLOUDThe cloud environment.static java.lang.StringCLOUD_FOUNDRYRunning on Cloud Foundry.static java.lang.StringCLOUD_PLATFORM_PROPERTYThe default bootstrap name.static java.lang.StringDEDUCE_ENVIRONMENT_ENVEnvironment key for whether to deduce environments.static java.lang.StringDEDUCE_ENVIRONMENT_PROPERTYProperty for whether to deduce environments.static java.lang.StringDEFAULT_NAMEThe default application name.static java.lang.StringDEVELOPMENTThe development environment.static java.lang.StringDIGITAL_OCEANCloud provider Digital Ocean.static java.lang.StringENVIRONMENTS_ENVThe environment key that stores additional environments.static java.lang.StringENVIRONMENTS_PROPERTYThe property that stores additional environments.static java.lang.StringFUNCTIONThe application is executing as a function.static java.lang.StringGAECloud provider for google app engine.static java.lang.StringGOOGLE_COMPUTECloud provider google compute instance.static java.lang.StringHEROKURunning on Heroku.static java.lang.StringHOSTNAMEThe host name environment variable.static java.lang.StringIBMCloud provider IBM cloud.static java.lang.StringKUBERNETESRunning on Kubernetes.static java.lang.StringMICRONAUTConstant for the name micronaut.static java.lang.StringORACLE_CLOUDCloud provider Oracle Cloud.static java.lang.StringPROPERTY_SOURCES_KEYThe key used to load additional property sources.static java.lang.StringTESTThe test environment.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description EnvironmentaddConfigurationExcludes(java.lang.String... names)Exclude configurations by name.EnvironmentaddConfigurationIncludes(java.lang.String... names)Exclude configurations by name.default EnvironmentaddPackage(java.lang.Package pkg)Add an application package.EnvironmentaddPackage(java.lang.String pkg)Add an application package.EnvironmentaddPropertySource(PropertySource propertySource)Adds a property source to this environment.default EnvironmentaddPropertySource(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.ClassLoadergetClassLoader()java.util.Collection<java.lang.String>getPackages()PropertyPlaceholderResolvergetPlaceholderResolver()java.util.Collection<PropertySourceLoader>getPropertySourceLoaders()Obtains thePropertySourceLoaderinstances.java.util.Collection<PropertySource>getPropertySources()booleanisActive(BeanConfiguration configuration)Whether the current environment includes the given configuration.default booleanisPresent(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 ofPropertySourceinstances and return a diff of the changes.EnvironmentremovePropertySource(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.-
Methods inherited from interface io.micronaut.core.convert.ConversionService
addConverter, addConverter, canConvert, convert, convert, convert, convert, convertRequired, convertRequired
-
Methods inherited from interface io.micronaut.context.LifeCycle
close, isRunning, refresh, start, stop
-
Methods inherited from interface io.micronaut.core.value.PropertyResolver
containsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyEntries, getRequiredProperty
-
-
-
-
Field Detail
-
MICRONAUT
static final java.lang.String MICRONAUT
Constant for the name micronaut.- See Also:
- Constant Field Values
-
TEST
static final java.lang.String TEST
The test environment.- See Also:
- Constant Field Values
-
DEVELOPMENT
static final java.lang.String DEVELOPMENT
The development environment.- See Also:
- Constant Field Values
-
ANDROID
static final java.lang.String ANDROID
The android environment.- See Also:
- Constant Field Values
-
CLI
static final java.lang.String CLI
The cli environment.- See Also:
- Constant Field Values
-
CLOUD
static final java.lang.String CLOUD
The cloud environment.- See Also:
- Constant Field Values
-
FUNCTION
static final java.lang.String FUNCTION
The application is executing as a function.- See Also:
- Constant Field Values
-
BOOTSTRAP_NAME_PROPERTY
static final java.lang.String BOOTSTRAP_NAME_PROPERTY
System property to override the default bootstrap name.- See Also:
- Constant Field Values
-
BOOTSTRAP_CONTEXT_PROPERTY
static final java.lang.String BOOTSTRAP_CONTEXT_PROPERTY
Whether the bootstrap context is enabled.- See Also:
- Constant Field Values
-
CLOUD_PLATFORM_PROPERTY
static final java.lang.String CLOUD_PLATFORM_PROPERTY
The default bootstrap name.- See Also:
- Constant Field Values
-
ENVIRONMENTS_PROPERTY
static final java.lang.String ENVIRONMENTS_PROPERTY
The property that stores additional environments.- See Also:
- Constant Field Values
-
ENVIRONMENTS_ENV
static final java.lang.String ENVIRONMENTS_ENV
The environment key that stores additional environments.- See Also:
- Constant Field Values
-
BOOTSTRAP_NAME
static final java.lang.String BOOTSTRAP_NAME
The default bootstrap config name.- See Also:
- Constant Field Values
-
DEFAULT_NAME
static final java.lang.String DEFAULT_NAME
The default application name.- See Also:
- Constant Field Values
-
GOOGLE_COMPUTE
static final java.lang.String GOOGLE_COMPUTE
Cloud provider google compute instance.- See Also:
- Constant Field Values
-
GAE
static final java.lang.String GAE
Cloud provider for google app engine.- See Also:
- Constant Field Values
-
AMAZON_EC2
static final java.lang.String AMAZON_EC2
Cloud provider amazon ec2.- See Also:
- Constant Field Values
-
AZURE
static final java.lang.String AZURE
Cloud provider Microsoft Azure.- See Also:
- Constant Field Values
-
ORACLE_CLOUD
static final java.lang.String ORACLE_CLOUD
Cloud provider Oracle Cloud.- See Also:
- Constant Field Values
-
DIGITAL_OCEAN
static final java.lang.String DIGITAL_OCEAN
Cloud provider Digital Ocean.- See Also:
- Constant Field Values
-
BARE_METAL
static final java.lang.String BARE_METAL
Cloud or non cloud provider on bare metal (unknown).- See Also:
- Constant Field Values
-
IBM
static final java.lang.String IBM
Cloud provider IBM cloud.- See Also:
- Constant Field Values
-
KUBERNETES
static final java.lang.String KUBERNETES
Running on Kubernetes.- See Also:
- Constant Field Values
-
CLOUD_FOUNDRY
static final java.lang.String CLOUD_FOUNDRY
Running on Cloud Foundry.- See Also:
- Constant Field Values
-
HEROKU
static final java.lang.String HEROKU
Running on Heroku.- See Also:
- Constant Field Values
-
PROPERTY_SOURCES_KEY
static final java.lang.String PROPERTY_SOURCES_KEY
The key used to load additional property sources.- See Also:
- Constant Field Values
-
HOSTNAME
static final java.lang.String HOSTNAME
The host name environment variable.- See Also:
- Constant Field Values
-
DEDUCE_ENVIRONMENT_PROPERTY
static final java.lang.String DEDUCE_ENVIRONMENT_PROPERTY
Property for whether to deduce environments.- See Also:
- Constant Field Values
-
DEDUCE_ENVIRONMENT_ENV
static final java.lang.String DEDUCE_ENVIRONMENT_ENV
Environment key for whether to deduce environments.- See Also:
- Constant Field Values
-
-
Method Detail
-
getActiveNames
java.util.Set<java.lang.String> getActiveNames()
Should respect the order as provided.- Returns:
- The active environment names
-
getPropertySources
java.util.Collection<PropertySource> getPropertySources()
- Returns:
- The active property sources
-
addPropertySource
Environment addPropertySource(PropertySource propertySource)
Adds a property source to this environment.- Parameters:
propertySource- The property source- Returns:
- This environment
-
removePropertySource
Environment removePropertySource(PropertySource propertySource)
Removes a property source from this environment.- Parameters:
propertySource- The property source- Returns:
- This environment
-
addPackage
Environment addPackage(java.lang.String pkg)
Add an application package. Application packages are candidates for scanning for tools that need it (such as JPA or GORM).- Parameters:
pkg- The package to add- Returns:
- This environment
-
addConfigurationExcludes
Environment addConfigurationExcludes(java.lang.String... names)
Exclude configurations by name.- Parameters:
names- The names of the configuration- Returns:
- This environment
-
addConfigurationIncludes
Environment addConfigurationIncludes(java.lang.String... names)
Exclude configurations by name.- Parameters:
names- The names of the configuration- Returns:
- This environment
-
getPackages
java.util.Collection<java.lang.String> getPackages()
- Returns:
- The application packages
-
getPlaceholderResolver
PropertyPlaceholderResolver getPlaceholderResolver()
- Returns:
- The placeholder resolver
-
refreshAndDiff
java.util.Map<java.lang.String,java.lang.Object> refreshAndDiff()
Refresh the environment from the list ofPropertySourceinstances and return a diff of the changes.- Returns:
- The values that changed
-
addPropertySource
default Environment addPropertySource(java.lang.String name, @Nullable java.util.Map<java.lang.String,? super java.lang.Object> values)
Add a property source for the given map.- Parameters:
name- The namevalues- The values- Returns:
- This environment
-
addPackage
default Environment addPackage(java.lang.Package pkg)
Add an application package. Application packages are candidates for scanning for tools that need it (such as JPA or GORM).- Parameters:
pkg- The package to add- Returns:
- This environment
-
scan
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. Use with care, repeated invocations should be avoided for performance reasons.- Parameters:
annotation- The annotation to scan- Returns:
- The classes
-
scan
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. 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
default java.lang.ClassLoader getClassLoader()
- Returns:
- The class loader for the environment
-
isPresent
default boolean isPresent(java.lang.String className)
Check whether the given class is present within this environment.- Parameters:
className- The class name- Returns:
- True if it is
-
isActive
boolean isActive(BeanConfiguration configuration)
Whether the current environment includes the given configuration.- Parameters:
configuration- The configuration- Returns:
- True if it does
-
getPropertySourceLoaders
java.util.Collection<PropertySourceLoader> getPropertySourceLoaders()
Obtains thePropertySourceLoaderinstances.- Returns:
- A collection of
PropertySourceLoader
-
-