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 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(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.
|
protected void |
addDefaultPropertySources(List<PropertySource> propertySources)
Adds default property sources.
|
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 BeanIntrospectionScanner |
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() |
protected List<PropertySource> |
getConstantPropertySources() |
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. |
Environment |
removePropertySource(PropertySource propertySource)
Removes a property source from this environment.
|
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, 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 List<PropertySource> refreshablePropertySources
public DefaultEnvironment(@NonNull ApplicationContextConfiguration configuration)
configuration - The configurationpublic 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 Environment removePropertySource(PropertySource propertySource)
EnvironmentremovePropertySource in interface EnvironmentpropertySource - The property sourcepublic 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 BeanIntrospectionScanner createAnnotationScanner(ClassLoader classLoader)
classLoader - The class loaderprotected String getPropertySourceRootName()
protected void readPropertySources(String name)
name - The name to read property sourcesprotected List<PropertySource> getConstantPropertySources()
protected 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 void addDefaultPropertySources(List<PropertySource> propertySources)
propertySources - The list of property sourcesprotected SoftServiceLoader<PropertySourceLoader> readPropertySourceLoaders()
SoftServiceLoaderpublic Collection<PropertySourceLoader> getPropertySourceLoaders()
PropertySourceLoader instances.getPropertySourceLoaders in interface EnvironmentPropertySourceLoader