Package io.micronaut.context.env
Class DefaultEnvironment
java.lang.Object
io.micronaut.context.env.PropertySourcePropertyResolver
io.micronaut.context.env.DefaultEnvironment
- All Implemented Interfaces:
Environment,LifeCycle<Environment>,io.micronaut.core.convert.ConversionService,io.micronaut.core.convert.MutableConversionService,io.micronaut.core.io.ResourceLoader,io.micronaut.core.value.PropertyResolver,io.micronaut.core.value.ValueResolver<String>,Closeable,AutoCloseable
The default implementation of the Environment interface. Configures a named environment.
- Since:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class io.micronaut.context.env.PropertySourcePropertyResolver
PropertySourcePropertyResolver.PropertyCatalog -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.micronaut.core.convert.MutableConversionServiceprotected final List<PropertySource>protected final io.micronaut.core.io.scan.ClassPathResourceLoaderFields inherited from class io.micronaut.context.env.PropertySourcePropertyResolver
catalog, conversionService, log, nonGenerated, propertyPlaceholderResolver, propertySources, rawCatalogFields inherited from interface io.micronaut.core.convert.ConversionService
SHAREDFields inherited from interface io.micronaut.context.env.Environment
AMAZON_EC2, ANDROID, AZURE, BARE_METAL, BOOTSTRAP_CONTEXT_PROPERTY, BOOTSTRAP_NAME, BOOTSTRAP_NAME_PROPERTY, CLI, CLOUD, CLOUD_FOUNDRY, CLOUD_PLATFORM_PROPERTY, DEDUCE_CLOUD_ENVIRONMENT_ENV, DEDUCE_CLOUD_ENVIRONMENT_PROPERTY, DEDUCE_ENVIRONMENT_ENV, DEDUCE_ENVIRONMENT_PROPERTY, DEFAULT_NAME, DEVELOPMENT, DIGITAL_OCEAN, ENVIRONMENTS_ENV, ENVIRONMENTS_PROPERTY, FUNCTION, GAE, GOOGLE_COMPUTE, HEROKU, HOSTNAME, IBM, KUBERNETES, MICRONAUT, ORACLE_CLOUD, PROPERTY_SOURCES_KEY, TEST -
Constructor Summary
ConstructorsConstructorDescriptionDefaultEnvironment(@NonNull ApplicationContextConfiguration configuration) Construct a new environment for the given configuration.DefaultEnvironment(@NonNull ApplicationContextConfiguration configuration, boolean logEnabled) Construct a new environment for the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionaddConfigurationExcludes(@Nullable String... names) Exclude configurations by name.addConfigurationIncludes(String... names) Exclude configurations by name.<S,T> void addConverter(Class<S> sourceType, Class<T> targetType, io.micronaut.core.convert.TypeConverter<S, T> typeConverter) <S,T> void addConverter(Class<S> sourceType, Class<T> targetType, Function<S, T> typeConverter) protected voidaddDefaultPropertySources(List<PropertySource> propertySources) Adds default property sources.addPackage(String pkg) Add an application package.addPropertySource(PropertySource propertySource) Add aPropertySourceto this resolver.addPropertySource(String name, Map<String, ? super Object> values) Add a property source for the given map.<S,T> boolean canConvert(Class<S> sourceType, Class<T> targetType) voidclose()Delegates toLifeCycle.stop().<T> Optional<T><S,T> Optional<T> convert(S object, Class<? super S> sourceType, Class<T> targetType, io.micronaut.core.convert.ConversionContext context) protected io.micronaut.core.io.scan.BeanIntrospectionScannercreateAnnotationScanner(ClassLoader classLoader) Creates the default annotation scanner.io.micronaut.core.io.ResourceLoaderShould respect the order as provided.protected List<PropertySource>io.micronaut.core.convert.MutableConversionServiceObtains thePropertySourceLoaderinstances.protected StringgetResource(String path) getResourceAsStream(String path) getResources(String path) booleanisActive(BeanConfiguration configuration) Whether the current environment includes the given configuration.booleanCheck whether the given class is present within this environment.booleanprotected List<PropertySource>readPropertySourceList(String name) protected List<PropertySource>Resolve the property sources for files passed via system property and system env.protected StringReads the value of MICRONAUT_CONFIG_FILES environment variable.protected io.micronaut.core.io.service.SoftServiceLoader<PropertySourceLoader>protected voidreadPropertySources(String name) 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.protected booleanprotected booleanstart()Starts the lifecyle component.stop()Stops the life cycle component.booleansupportsPrefix(String path) Methods inherited from class io.micronaut.context.env.PropertySourcePropertyResolver
containsProperties, containsProperty, getAllProperties, getProperties, getProperty, getPropertyEntries, getPropertyPathMatches, processPropertySource, resetCaches, resolveEntriesForKey, resolveSubMap, resolveSubMap, resolveSubPropertiesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.core.convert.ConversionService
convert, convert, convert, convert, convertRequired, convertRequired, convertRequiredMethods inherited from interface io.micronaut.context.env.Environment
addPackageMethods inherited from interface io.micronaut.core.value.PropertyResolver
containsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyEntries, getPropertyPathMatches, getRequiredPropertyMethods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get
-
Field Details
-
resourceLoader
protected final io.micronaut.core.io.scan.ClassPathResourceLoader resourceLoader -
refreshablePropertySources
-
mutableConversionService
protected final io.micronaut.core.convert.MutableConversionService mutableConversionService
-
-
Constructor Details
-
DefaultEnvironment
Construct a new environment for the given configuration.- Parameters:
configuration- The configuration
-
DefaultEnvironment
public DefaultEnvironment(@NonNull @NonNull ApplicationContextConfiguration configuration, boolean logEnabled) Construct a new environment for the given configuration.- Parameters:
configuration- The configurationlogEnabled- flag to enable or disable logger
-
-
Method Details
-
isPresent
Description copied from interface:EnvironmentCheck whether the given class is present within this environment.- Specified by:
isPresentin interfaceEnvironment- Parameters:
className- The class name- Returns:
- True if it is
-
getPlaceholderResolver
- Specified by:
getPlaceholderResolverin interfaceEnvironment- Returns:
- The placeholder resolver
-
scan
Description copied from interface:EnvironmentScan the current environment for classes annotated with the given annotation. Use with care, repeated invocations should be avoided for performance reasons.- Specified by:
scanin interfaceEnvironment- Parameters:
annotation- The annotation to scan- Returns:
- The classes
-
scan
Description copied from interface:EnvironmentScan the current environment for classes annotated with the given annotation. Use with care, repeated invocations should be avoided for performance reasons.- Specified by:
scanin interfaceEnvironment- Parameters:
annotation- The annotation to scanpackages- The packages to scan- Returns:
- The classes
-
getClassLoader
- Specified by:
getClassLoaderin interfaceEnvironment- Returns:
- The class loader for the environment
-
isActive
Description copied from interface:EnvironmentWhether the current environment includes the given configuration.- Specified by:
isActivein interfaceEnvironment- Parameters:
configuration- The configuration- Returns:
- True if it does
-
addPropertySource
Description copied from class:PropertySourcePropertyResolverAdd aPropertySourceto this resolver.- Specified by:
addPropertySourcein interfaceEnvironment- Overrides:
addPropertySourcein classPropertySourcePropertyResolver- Parameters:
propertySource- ThePropertySourceto add- Returns:
- This
PropertySourcePropertyResolver
-
removePropertySource
Description copied from interface:EnvironmentRemoves a property source from this environment.- Specified by:
removePropertySourcein interfaceEnvironment- Parameters:
propertySource- The property source- Returns:
- This environment
-
addPropertySource
Description copied from class:PropertySourcePropertyResolverAdd a property source for the given map.- Specified by:
addPropertySourcein interfaceEnvironment- Overrides:
addPropertySourcein classPropertySourcePropertyResolver- Parameters:
name- The name of the property sourcevalues- The values- Returns:
- This environment
-
addPackage
Description copied from interface:EnvironmentAdd an application package. Application packages are candidates for scanning for tools that need it (such as JPA or GORM).- Specified by:
addPackagein interfaceEnvironment- Parameters:
pkg- The package to add- Returns:
- This environment
-
addConfigurationExcludes
Description copied from interface:EnvironmentExclude configurations by name.- Specified by:
addConfigurationExcludesin interfaceEnvironment- Parameters:
names- The names of the configuration- Returns:
- This environment
-
addConfigurationIncludes
Description copied from interface:EnvironmentExclude configurations by name.- Specified by:
addConfigurationIncludesin interfaceEnvironment- Parameters:
names- The names of the configuration- Returns:
- This environment
-
getPackages
- Specified by:
getPackagesin interfaceEnvironment- Returns:
- The application packages
-
getActiveNames
Description copied from interface:EnvironmentShould respect the order as provided.- Specified by:
getActiveNamesin interfaceEnvironment- Returns:
- The active environment names
-
getPropertySources
- Specified by:
getPropertySourcesin interfaceEnvironment- Returns:
- The active property sources
-
start
Description copied from interface:LifeCycleStarts the lifecyle component.- Specified by:
startin interfaceLifeCycle<Environment>- Returns:
- This lifecycle component
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceLifeCycle<Environment>- Returns:
- Whether the component is running
-
stop
Description copied from interface:LifeCycleStops the life cycle component.- Specified by:
stopin interfaceLifeCycle<Environment>- Returns:
- This lifecycle component
-
refreshAndDiff
Description copied from interface:EnvironmentRefresh the environment from the list ofPropertySourceinstances and return a diff of the changes.- Specified by:
refreshAndDiffin interfaceEnvironment- Returns:
- The values that changed
-
convert
public <T> Optional<T> convert(Object object, Class<T> targetType, io.micronaut.core.convert.ConversionContext context) - Specified by:
convertin interfaceio.micronaut.core.convert.ConversionService
-
convert
public <S,T> Optional<T> convert(S object, Class<? super S> sourceType, Class<T> targetType, io.micronaut.core.convert.ConversionContext context) - Specified by:
convertin interfaceio.micronaut.core.convert.ConversionService
-
canConvert
- Specified by:
canConvertin interfaceio.micronaut.core.convert.ConversionService
-
addConverter
public <S,T> void addConverter(Class<S> sourceType, Class<T> targetType, io.micronaut.core.convert.TypeConverter<S, T> typeConverter) - Specified by:
addConverterin interfaceio.micronaut.core.convert.MutableConversionService
-
addConverter
public <S,T> void addConverter(Class<S> sourceType, Class<T> targetType, Function<S, T> typeConverter) - Specified by:
addConverterin interfaceio.micronaut.core.convert.MutableConversionService
-
getMutableConversionService
@Internal public io.micronaut.core.convert.MutableConversionService getMutableConversionService()- Returns:
- The mutable conversion service.
-
getResourceAsStream
- Specified by:
getResourceAsStreamin interfaceio.micronaut.core.io.ResourceLoader
-
getResource
- Specified by:
getResourcein interfaceio.micronaut.core.io.ResourceLoader
-
getResources
- Specified by:
getResourcesin interfaceio.micronaut.core.io.ResourceLoader
-
supportsPrefix
- Specified by:
supportsPrefixin interfaceio.micronaut.core.io.ResourceLoader
-
forBase
- Specified by:
forBasein interfaceio.micronaut.core.io.ResourceLoader
-
shouldDeduceEnvironments
protected boolean shouldDeduceEnvironments()- Returns:
- Whether environment names and packages should be deduced
-
shouldDeduceCloudEnvironment
protected boolean shouldDeduceCloudEnvironment()- Returns:
- Whether cloud environment should be deduced based on environment variable, system property or configuration
-
createAnnotationScanner
protected io.micronaut.core.io.scan.BeanIntrospectionScanner createAnnotationScanner(ClassLoader classLoader) Creates the default annotation scanner.- Parameters:
classLoader- The class loader- Returns:
- The scanner
-
getPropertySourceRootName
- Returns:
- The property source root name
-
readPropertySources
- Parameters:
name- The name to read property sources
-
getConstantPropertySources
- Returns:
- Property sources created at build time
-
readPropertySourceListKeyFromEnvironment
Reads the value of MICRONAUT_CONFIG_FILES environment variable.- Returns:
- The comma-separated list of files
-
readPropertySourceListFromFiles
Resolve the property sources for files passed via system property and system env.- Parameters:
files- The comma separated list of files- Returns:
- The list of property sources for each file
-
readPropertySourceList
- Parameters:
name- The name to resolver property sources- Returns:
- The list of property sources
-
addDefaultPropertySources
Adds default property sources.- Parameters:
propertySources- The list of property sources
-
readPropertySourceLoaders
protected io.micronaut.core.io.service.SoftServiceLoader<PropertySourceLoader> readPropertySourceLoaders()- Returns:
- Loaded properties as a
SoftServiceLoader
-
getPropertySourceLoaders
Obtains thePropertySourceLoaderinstances.- Specified by:
getPropertySourceLoadersin interfaceEnvironment- Returns:
- A collection of
PropertySourceLoader
-
close
public void close()Description copied from interface:LifeCycleDelegates toLifeCycle.stop().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceLifeCycle<Environment>- Overrides:
closein classPropertySourcePropertyResolver
-