public class DefaultEnvironment extends PropertySourcePropertyResolver implements Environment
The default implementation of the Environment interface. Configures a named environment.
| Modifier and Type | Field and Description | 
|---|---|
protected ClassPathResourceLoader | 
resourceLoader  | 
catalog, conversionService, propertyPlaceholderResolver, propertySourcesAMAZON_EC2, ANDROID, AZURE, BARE_METAL, BOOTSTRAP_NAME, BOOTSTRAP_NAME_PROPERTY, CLI, CLOUD, CLOUD_FOUNDRY, CLOUD_PLATFORM_PROPERTY, DEFAULT_NAME, DEVELOPMENT, ENVIRONMENTS_ENV, ENVIRONMENTS_PROPERTY, FUNCTION, GOOGLE_COMPUTE, HEROKU, HOSTNAME, IBM, KUBERNETES, MICRONAUT, PROPERTY_SOURCES_KEY, TESTSHARED| Constructor and Description | 
|---|
DefaultEnvironment(ClassLoader classLoader,
                  ConversionService conversionService,
                  String... names)  | 
DefaultEnvironment(ClassLoader classLoader,
                  String... names)  | 
DefaultEnvironment(ClassPathResourceLoader resourceLoader,
                  ConversionService conversionService,
                  String... names)  | 
DefaultEnvironment(String... names)  | 
| Modifier and Type | Method and Description | 
|---|---|
Environment | 
addConfigurationExcludes(String... names)
Exclude configurations by name. 
 | 
Environment | 
addConfigurationIncludes(String... names)
Exclude configurations by name. 
 | 
<S,T> Environment | 
addConverter(Class<S> sourceType,
            Class<T> targetType,
            Function<S,T> typeConverter)
Adds a type converter. 
 | 
<S,T> Environment | 
addConverter(Class<S> sourceType,
            Class<T> targetType,
            TypeConverter<S,T> typeConverter)
Adds a type converter. 
 | 
Environment | 
addPackage(String pkg)
Add an application package. 
 | 
DefaultEnvironment | 
addPropertySource(PropertySource propertySource)
Add a  
PropertySource to this resolver. | 
DefaultEnvironment | 
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)
Return whether the given source type is convertible to the given target type. 
 | 
<T> Optional<T> | 
convert(Object object,
       Class<T> targetType,
       ConversionContext context)
Attempts to convert the given object to the given target type. 
 | 
protected ClassPathAnnotationScanner | 
createAnnotationScanner(ClassLoader classLoader)
Creates the default annotation scanner. 
 | 
ResourceLoader | 
forBase(String basePath)
Constructs a new resource loader designed to load
 resources from the given path. 
 | 
Set<String> | 
getActiveNames()
Should respect the order as provided. 
 | 
ClassLoader | 
getClassLoader()  | 
Collection<String> | 
getPackages()  | 
PropertyPlaceholderResolver | 
getPlaceholderResolver()  | 
Collection<PropertySourceLoader> | 
getPropertySourceLoaders()
Obtains the  
PropertySourceLoader instances. | 
protected String | 
getPropertySourceRootName()  | 
Collection<PropertySource> | 
getPropertySources()  | 
Optional<URL> | 
getResource(String path)
Obtains the URL to a given resource. 
 | 
Optional<InputStream> | 
getResourceAsStream(String path)
Obtains a resource as a stream. 
 | 
Stream<URL> | 
getResources(String path)
Obtains all resources with the given name. 
 | 
boolean | 
isActive(BeanConfiguration configuration)
Whether the current environment includes the given configuration. 
 | 
boolean | 
isPresent(String className)
Check whether the given class is present within this environment. 
 | 
boolean | 
isRunning()  | 
protected List<PropertySource> | 
readPropertySourceList(String name)  | 
protected List<PropertySource> | 
readPropertySourceListFromFiles(String files)
Resolve the property sources for files passed via system property and system env. 
 | 
protected String | 
readPropertySourceListKeyFromEnvironment()
Reads the value of MICRONAUT_CONFIG_FILES environment variable. 
 | 
protected SoftServiceLoader<PropertySourceLoader> | 
readPropertySourceLoaders()  | 
protected void | 
readPropertySources(String name)  | 
Map<String,Object> | 
refreshAndDiff()
Refresh the environment from the list of  
PropertySource instances and return a diff of the changes. | 
Stream<Class> | 
scan(Class<? extends Annotation> annotation)
Scan the current environment for classes annotated with the given annotation. 
 | 
Stream<Class> | 
scan(Class<? extends Annotation> annotation,
    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(String path)  | 
containsProperties, containsProperty, getAllProperties, getProperties, getProperty, processPropertySource, resetCaches, resolveEntriesForKey, resolveSubMap, resolveSubMap, resolveSubPropertiesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddPackagecontainsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getRequiredProperty, nameOfget, get, getconvert, convert, convertprotected final ClassPathResourceLoader resourceLoader
public DefaultEnvironment(ClassLoader classLoader, String... names)
classLoader - The class loadernames - The namespublic DefaultEnvironment(String... names)
names - The namespublic DefaultEnvironment(ClassLoader classLoader, ConversionService conversionService, String... names)
classLoader - The class loaderconversionService - The conversion servicenames - The namespublic DefaultEnvironment(ClassPathResourceLoader resourceLoader, ConversionService conversionService, String... names)
resourceLoader - The resource loaderconversionService - The conversion servicenames - The namespublic boolean isPresent(String className)
EnvironmentisPresent in interface EnvironmentclassName - The class namepublic PropertyPlaceholderResolver getPlaceholderResolver()
getPlaceholderResolver in interface Environmentpublic Stream<Class> scan(Class<? extends Annotation> annotation)
Environmentscan in interface Environmentannotation - The annotation to scanpublic Stream<Class> scan(Class<? extends Annotation> annotation, String... packages)
Environmentscan in interface Environmentannotation - The annotation to scanpackages - The packages to scanpublic 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 DefaultEnvironment addPropertySource(String name, Map<String,? super Object> values)
PropertySourcePropertyResolveraddPropertySource in interface EnvironmentaddPropertySource in class PropertySourcePropertyResolvername - The name of the property sourcevalues - The valuespublic Environment addPackage(String pkg)
EnvironmentaddPackage in interface Environmentpkg - The package to addpublic Environment addConfigurationExcludes(@Nullable String... names)
EnvironmentaddConfigurationExcludes in interface Environmentnames - The names of the configurationpublic Environment addConfigurationIncludes(String... names)
EnvironmentaddConfigurationIncludes in interface Environmentnames - The names of the configurationpublic Collection<String> getPackages()
getPackages in interface Environmentpublic Set<String> getActiveNames()
EnvironmentgetActiveNames in interface Environmentpublic 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 Map<String,Object> refreshAndDiff()
EnvironmentPropertySource instances and return a diff of the changes.refreshAndDiff in interface Environmentpublic <T> Optional<T> convert(Object object, 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(Class<S> sourceType, 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(Class<S> sourceType, 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(Class<S> sourceType, Class<T> targetType, 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 Optional<InputStream> getResourceAsStream(String path)
ResourceLoadergetResourceAsStream in interface ResourceLoaderpath - The pathpublic Optional<URL> getResource(String path)
ResourceLoadergetResource in interface ResourceLoaderpath - The pathpublic Stream<URL> getResources(String path)
ResourceLoadergetResources in interface ResourceLoaderpath - The name of the resourcepublic boolean supportsPrefix(String path)
supportsPrefix in interface ResourceLoaderpath - The path to a resource including a prefix
             appended by a colon. Ex (classpath:, file:)public ResourceLoader forBase(String basePath)
ResourceLoaderforBase in interface ResourceLoaderbasePath - The path to load resourcesResourceLoaderprotected boolean shouldDeduceEnvironments()
protected ClassPathAnnotationScanner createAnnotationScanner(ClassLoader classLoader)
classLoader - The class loaderprotected String getPropertySourceRootName()
protected void readPropertySources(String name)
name - The name to read property sourcesprotected String readPropertySourceListKeyFromEnvironment()
protected List<PropertySource> readPropertySourceListFromFiles(String files)
files - The comma separated list of filesprotected List<PropertySource> readPropertySourceList(String name)
name - The name to resolver property sourcesprotected SoftServiceLoader<PropertySourceLoader> readPropertySourceLoaders()
SoftServiceLoaderpublic Collection<PropertySourceLoader> getPropertySourceLoaders()
PropertySourceLoader instances.getPropertySourceLoaders in interface EnvironmentPropertySourceLoader