public class DefaultEnvironment extends PropertySourcePropertyResolver implements Environment
The default implementation of the Environment interface. Configures a named environment.
PropertySourcePropertyResolver.PropertyCatalog| Modifier and Type | Field and Description | 
|---|---|
protected java.util.List<PropertySource> | 
refreshablePropertySources  | 
protected ClassPathResourceLoader | 
resourceLoader  | 
catalog, conversionService, nonGenerated, propertyPlaceholderResolver, propertySources, rawCatalogAMAZON_EC2, ANDROID, AZURE, BARE_METAL, BOOTSTRAP_CONTEXT_PROPERTY, BOOTSTRAP_NAME, BOOTSTRAP_NAME_PROPERTY, CLI, CLOUD, CLOUD_FOUNDRY, CLOUD_PLATFORM_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, TESTSHARED| Constructor and Description | 
|---|
DefaultEnvironment(ApplicationContextConfiguration configuration)
Construct a new environment for the given configuration. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
Environment | 
addConfigurationExcludes(java.lang.String... names)
Exclude configurations by name. 
 | 
Environment | 
addConfigurationIncludes(java.lang.String... names)
Exclude configurations by name. 
 | 
<S,T> Environment | 
addConverter(java.lang.Class<S> sourceType,
            java.lang.Class<T> targetType,
            java.util.function.Function<S,T> typeConverter)
Adds a type converter. 
 | 
<S,T> Environment | 
addConverter(java.lang.Class<S> sourceType,
            java.lang.Class<T> targetType,
            TypeConverter<S,T> typeConverter)
Adds a type converter. 
 | 
protected void | 
addDefaultPropertySources(java.util.List<PropertySource> propertySources)
Adds default property sources. 
 | 
Environment | 
addPackage(java.lang.String pkg)
Add an application package. 
 | 
DefaultEnvironment | 
addPropertySource(PropertySource propertySource)
Add a  
PropertySource to this resolver. | 
DefaultEnvironment | 
addPropertySource(java.lang.String name,
                 java.util.Map<java.lang.String,? super java.lang.Object> values)
Add a property source for the given map. 
 | 
<S,T> boolean | 
canConvert(java.lang.Class<S> sourceType,
          java.lang.Class<T> targetType)
Return whether the given source type is convertible to the given target type. 
 | 
<T> java.util.Optional<T> | 
convert(java.lang.Object object,
       java.lang.Class<T> targetType,
       ConversionContext context)
Attempts to convert the given object to the given target type. 
 | 
protected BeanIntrospectionScanner | 
createAnnotationScanner(java.lang.ClassLoader classLoader)
Creates the default annotation scanner. 
 | 
ResourceLoader | 
forBase(java.lang.String basePath)
Constructs a new resource loader designed to load
 resources from the given path. 
 | 
java.util.Set<java.lang.String> | 
getActiveNames()
Should respect the order as provided. 
 | 
java.lang.ClassLoader | 
getClassLoader()  | 
java.util.Collection<java.lang.String> | 
getPackages()  | 
PropertyPlaceholderResolver | 
getPlaceholderResolver()  | 
java.util.Collection<PropertySourceLoader> | 
getPropertySourceLoaders()
Obtains the  
PropertySourceLoader instances. | 
protected java.lang.String | 
getPropertySourceRootName()  | 
java.util.Collection<PropertySource> | 
getPropertySources()  | 
java.util.Optional<java.net.URL> | 
getResource(java.lang.String path)
Obtains the URL to a given resource. 
 | 
java.util.Optional<java.io.InputStream> | 
getResourceAsStream(java.lang.String path)
Obtains a resource as a stream. 
 | 
java.util.stream.Stream<java.net.URL> | 
getResources(java.lang.String path)
Obtains all resources with the given name. 
 | 
boolean | 
isActive(BeanConfiguration configuration)
Whether the current environment includes the given configuration. 
 | 
boolean | 
isPresent(java.lang.String className)
Check whether the given class is present within this environment. 
 | 
boolean | 
isRunning()  | 
protected java.util.List<PropertySource> | 
readPropertySourceList(java.lang.String name)  | 
protected java.util.List<PropertySource> | 
readPropertySourceListFromFiles(java.lang.String files)
Resolve the property sources for files passed via system property and system env. 
 | 
protected java.lang.String | 
readPropertySourceListKeyFromEnvironment()
Reads the value of MICRONAUT_CONFIG_FILES environment variable. 
 | 
protected SoftServiceLoader<PropertySourceLoader> | 
readPropertySourceLoaders()  | 
protected void | 
readPropertySources(java.lang.String name)  | 
java.util.Map<java.lang.String,java.lang.Object> | 
refreshAndDiff()
Refresh the environment from the list of  
PropertySource instances and return a diff of the changes. | 
Environment | 
removePropertySource(PropertySource propertySource)
Removes a property source from this environment. 
 | 
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. 
 | 
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. 
 | 
protected boolean | 
shouldDeduceEnvironments()  | 
Environment | 
start()
Starts the lifecyle component. 
 | 
Environment | 
stop()
Stops the life cycle component. 
 | 
boolean | 
supportsPrefix(java.lang.String path)  | 
containsProperties, containsProperty, getAllProperties, getProperties, getProperty, getPropertyEntries, processPropertySource, resetCaches, resolveEntriesForKey, resolveEntriesForKey, resolveSubMap, resolveSubMap, resolveSubPropertiesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddPackagecontainsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyEntries, getRequiredProperty, nameOfget, get, getconvert, convert, convert, convertRequired, convertRequiredprotected final ClassPathResourceLoader resourceLoader
protected final java.util.List<PropertySource> refreshablePropertySources
public DefaultEnvironment(@NonNull ApplicationContextConfiguration configuration)
configuration - The configurationpublic boolean isPresent(java.lang.String className)
EnvironmentisPresent in interface EnvironmentclassName - The class namepublic PropertyPlaceholderResolver getPlaceholderResolver()
getPlaceholderResolver in interface Environmentpublic java.util.stream.Stream<java.lang.Class<?>> scan(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Environmentscan in interface Environmentannotation - The annotation to scanpublic java.util.stream.Stream<java.lang.Class<?>> scan(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
                                                        java.lang.String... packages)
Environmentscan in interface Environmentannotation - The annotation to scanpackages - The packages to scanpublic java.lang.ClassLoader getClassLoader()
getClassLoader in interface Environmentpublic boolean isActive(BeanConfiguration configuration)
EnvironmentisActive in interface Environmentconfiguration - The configurationpublic DefaultEnvironment addPropertySource(PropertySource propertySource)
PropertySourcePropertyResolverPropertySource to this resolver.addPropertySource in interface EnvironmentaddPropertySource in class PropertySourcePropertyResolverpropertySource - The PropertySource to addPropertySourcePropertyResolverpublic Environment removePropertySource(PropertySource propertySource)
EnvironmentremovePropertySource in interface EnvironmentpropertySource - The property sourcepublic DefaultEnvironment addPropertySource(java.lang.String name, java.util.Map<java.lang.String,? super java.lang.Object> values)
PropertySourcePropertyResolveraddPropertySource in interface EnvironmentaddPropertySource in class PropertySourcePropertyResolvername - The name of the property sourcevalues - The valuespublic Environment addPackage(java.lang.String pkg)
EnvironmentaddPackage in interface Environmentpkg - The package to addpublic Environment addConfigurationExcludes(@Nullable java.lang.String... names)
EnvironmentaddConfigurationExcludes in interface Environmentnames - The names of the configurationpublic Environment addConfigurationIncludes(java.lang.String... names)
EnvironmentaddConfigurationIncludes in interface Environmentnames - The names of the configurationpublic java.util.Collection<java.lang.String> getPackages()
getPackages in interface Environmentpublic java.util.Set<java.lang.String> getActiveNames()
EnvironmentgetActiveNames in interface Environmentpublic java.util.Collection<PropertySource> getPropertySources()
getPropertySources in interface Environmentpublic Environment start()
LifeCyclestart in interface LifeCycle<Environment>public boolean isRunning()
isRunning in interface LifeCycle<Environment>public Environment stop()
LifeCyclestop in interface LifeCycle<Environment>public java.util.Map<java.lang.String,java.lang.Object> refreshAndDiff()
EnvironmentPropertySource instances and return a diff of the changes.refreshAndDiff in interface Environmentpublic <T> java.util.Optional<T> convert(java.lang.Object object,
                                         java.lang.Class<T> targetType,
                                         ConversionContext context)
ConversionServiceOptional is returned.convert in interface ConversionService<Environment>T - The generic typeobject - The object to converttargetType - The target typecontext - The conversion contextpublic <S,T> boolean canConvert(java.lang.Class<S> sourceType,
                                java.lang.Class<T> targetType)
ConversionServicecanConvert in interface ConversionService<Environment>S - The generic source typeT - The target source typesourceType - The source typetargetType - The target typepublic <S,T> Environment addConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, TypeConverter<S,T> typeConverter)
ConversionServiceaddConverter in interface ConversionService<Environment>S - The source generic typeT - The target generic typesourceType - The source typetargetType - The target typetypeConverter - The type converterpublic <S,T> Environment addConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType, java.util.function.Function<S,T> typeConverter)
ConversionServiceaddConverter in interface ConversionService<Environment>S - The source generic typeT - The target generic typesourceType - The source typetargetType - The target typetypeConverter - The type converterpublic java.util.Optional<java.io.InputStream> getResourceAsStream(java.lang.String path)
ResourceLoadergetResourceAsStream in interface ResourceLoaderpath - The pathpublic java.util.Optional<java.net.URL> getResource(java.lang.String path)
ResourceLoadergetResource in interface ResourceLoaderpath - The pathpublic java.util.stream.Stream<java.net.URL> getResources(java.lang.String path)
ResourceLoadergetResources in interface ResourceLoaderpath - The name of the resourcepublic boolean supportsPrefix(java.lang.String path)
supportsPrefix in interface ResourceLoaderpath - The path to a resource including a prefix
             appended by a colon. Ex (classpath:, file:)public ResourceLoader forBase(java.lang.String basePath)
ResourceLoaderforBase in interface ResourceLoaderbasePath - The path to load resourcesResourceLoaderprotected boolean shouldDeduceEnvironments()
protected BeanIntrospectionScanner createAnnotationScanner(java.lang.ClassLoader classLoader)
classLoader - The class loaderprotected java.lang.String getPropertySourceRootName()
protected void readPropertySources(java.lang.String name)
name - The name to read property sourcesprotected java.lang.String readPropertySourceListKeyFromEnvironment()
protected java.util.List<PropertySource> readPropertySourceListFromFiles(java.lang.String files)
files - The comma separated list of filesprotected java.util.List<PropertySource> readPropertySourceList(java.lang.String name)
name - The name to resolver property sourcesprotected void addDefaultPropertySources(java.util.List<PropertySource> propertySources)
propertySources - The list of property sourcesprotected SoftServiceLoader<PropertySourceLoader> readPropertySourceLoaders()
SoftServiceLoaderpublic java.util.Collection<PropertySourceLoader> getPropertySourceLoaders()
PropertySourceLoader instances.getPropertySourceLoaders in interface EnvironmentPropertySourceLoader