public class DefaultApplicationContext extends DefaultBeanContext implements ApplicationContext
ApplicationContext
interface.initializing, LOG, LOG_LIFECYCLE, running, terminating
EMPTY
NO_OP
Constructor and Description |
---|
DefaultApplicationContext(ApplicationContextConfiguration configuration)
Construct a new ApplicationContext for the given environment name and classloader.
|
DefaultApplicationContext(io.micronaut.core.io.scan.ClassPathResourceLoader resourceLoader,
java.lang.String... environmentNames)
Construct a new ApplicationContext for the given environment name and classloader.
|
DefaultApplicationContext(java.lang.String... environmentNames)
Construct a new ApplicationContext for the given environment name.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsProperties(java.lang.String name) |
boolean |
containsProperty(java.lang.String name) |
protected io.micronaut.core.convert.ConversionService |
createConversionService()
Creates the default conversion service.
|
protected Environment |
createEnvironment(ApplicationContextConfiguration configuration)
Creates the default environment for the given environment name.
|
protected <T> java.util.Collection<BeanDefinition<T>> |
findBeanCandidates(BeanResolutionContext resolutionContext,
io.micronaut.core.type.Argument<T> beanType,
BeanDefinition<?> filter,
boolean filterProxied)
Find bean candidates for the given type.
|
protected <T> java.util.Collection<BeanDefinition<T>> |
findBeanCandidates(BeanResolutionContext resolutionContext,
io.micronaut.core.type.Argument<T> beanType,
boolean filterProxied,
java.util.function.Predicate<BeanDefinition<T>> predicate)
Find bean candidates for the given type.
|
protected <T> BeanDefinition<T> |
findConcreteCandidate(java.lang.Class<T> beanType,
Qualifier<T> qualifier,
java.util.Collection<BeanDefinition<T>> candidates)
Fall back method to attempt to find a candidate for the given definitions.
|
io.micronaut.core.convert.ConversionService<?> |
getConversionService() |
Environment |
getEnvironment() |
java.util.Map<java.lang.String,java.lang.Object> |
getProperties(java.lang.String name,
io.micronaut.core.naming.conventions.StringConvention keyFormat) |
<T> java.util.Optional<T> |
getProperty(java.lang.String name,
io.micronaut.core.convert.ArgumentConversionContext<T> conversionContext) |
java.util.Collection<java.lang.String> |
getPropertyEntries(java.lang.String name) |
protected void |
initializeContext(java.util.List<BeanDefinitionReference> contextScopeBeans,
java.util.List<BeanDefinitionReference> processedBeans,
java.util.List<BeanDefinitionReference> parallelBeans)
Initialize the context with the given
Context scope beans. |
protected void |
initializeTypeConverters(BeanContext beanContext) |
protected void |
registerConfiguration(BeanConfiguration configuration)
Registers an active configuration.
|
<T> ApplicationContext |
registerSingleton(java.lang.Class<T> type,
T singleton,
Qualifier<T> qualifier,
boolean inject)
Registers a new singleton bean at runtime.
|
java.util.Optional<java.lang.String> |
resolvePlaceholders(java.lang.String str)
Resolve the placeholders and return an Optional String if it was possible to resolve them.
|
java.lang.String |
resolveRequiredPlaceholders(java.lang.String str)
Resolve the placeholders and return an Optional String if it was possible to resolve them.
|
ApplicationContext |
start()
The start method will read all bean definition classes found on the classpath and initialize any pre-required
state.
|
protected void |
startEnvironment()
Start the environment.
|
ApplicationContext |
stop()
The close method will shut down the context calling
PreDestroy hooks on loaded
singletons. |
protected <T> java.util.Collection<BeanDefinition<T>> |
transformIterables(BeanResolutionContext resolutionContext,
java.util.Collection<BeanDefinition<T>> candidates,
boolean filterProxied)
Method that transforms iterable candidates if possible.
|
containsBean, containsBean, createBean, createBean, createBean, createBean, createCustomScopeRegistry, createExecutionHandle, destroyBean, destroyBean, destroyBean, doCreateBean, doCreateBean, doCreateBean, finalizeConfiguration, findBean, findBean, findBean, findBean, findBeanCandidates, findBeanCandidatesForInstance, findBeanConfiguration, findBeanDefinition, findBeanDefinition, findBeanRegistration, findExecutableMethod, findExecutionHandle, findExecutionHandle, findExecutionHandle, findProxyBeanDefinition, findProxyBeanDefinition, findProxyTargetBeanDefinition, findProxyTargetBeanDefinition, findProxyTargetMethod, findProxyTargetMethod, findProxyTargetMethod, getActiveBeanRegistration, getActiveBeanRegistrations, getActiveBeanRegistrations, getAllBeanDefinitions, getAttribute, getAttribute, getAttributes, getBean, getBean, getBean, getBean, getBean, getBean, getBean, getBeanDefinition, getBeanDefinitionReferences, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanRegistration, getBeanRegistration, getBeanRegistration, getBeanRegistrations, getBeanRegistrations, getBeanRegistrations, getBeanRegistrations, getBeansOfType, getBeansOfType, getBeansOfType, getBeansOfType, getBeansOfType, getBeansOfType, getBeanValidator, getClassLoader, getContextConfiguration, getProxyTargetBean, getProxyTargetBean, getProxyTargetBean, initializeEventListeners, inject, inject, invalidateCaches, isRunning, processParallelBeans, publishEvent, publishEventAsync, refreshBean, removeAttribute, resolveBeanConfigurations, resolveBeanDefinitionReferences, resolveBeanDefinitionReferences, resolveMetadata, setAttribute, streamOfType, streamOfType, streamOfType, streamOfType
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
builder, builder, builder, builder, builder, environment, registerSingleton, registerSingleton, registerSingleton, registerSingleton, run, run, run, run, run, run, run, run
build, build, createBean, createBean, createBean, createBean, createBean, createBean, destroyBean, destroyBean, destroyBean, destroyBean, getBeanValidator, getClassLoader, getContextConfiguration, getEventPublisher, inject, publishEvent, publishEventAsync, refreshBean, run
createExecutionHandle, findExecutableMethod, findExecutionHandle, findExecutionHandle, findExecutionHandle, findProxyTargetMethod, findProxyTargetMethod, findProxyTargetMethod, getExecutableMethod, getExecutionHandle, getExecutionHandle, getProxyTargetMethod, getProxyTargetMethod, getProxyTargetMethod
findBean, findBean, findBean, findBean, findOrInstantiateBean, getBean, getBean, getBean, getBean, getBean, getBeansOfType, getBeansOfType, getBeansOfType, getBeansOfType, getProxyTargetBean, getProxyTargetBean, streamOfType, streamOfType, streamOfType, streamOfType
containsBean, containsBean, containsBean, containsBean, findBeanConfiguration, findBeanDefinition, findBeanDefinition, findBeanDefinition, findBeanDefinition, findBeanRegistration, findProxyBeanDefinition, findProxyBeanDefinition, findProxyTargetBeanDefinition, findProxyTargetBeanDefinition, getActiveBeanRegistrations, getActiveBeanRegistrations, getAllBeanDefinitions, getBeanDefinition, getBeanDefinition, getBeanDefinition, getBeanDefinition, getBeanDefinitionReferences, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanRegistration, getBeanRegistration, getBeanRegistrations, getBeanRegistrations, getBeanRegistrations, getProxyTargetBeanDefinition, getProxyTargetBeanDefinition
noOp
resolveMetadata, resolveMetadata
getAttributes, removeAttribute, setAttribute
get, getProperties, getProperty, getProperty, getProperty, getProperty, getRequiredProperty, nameOf
getPrefix, resolveRequiredPlaceholder
public DefaultApplicationContext(@NonNull java.lang.String... environmentNames)
environmentNames
- The environment namespublic DefaultApplicationContext(@NonNull io.micronaut.core.io.scan.ClassPathResourceLoader resourceLoader, @NonNull java.lang.String... environmentNames)
environmentNames
- The environment namesresourceLoader
- The class loaderpublic DefaultApplicationContext(@NonNull ApplicationContextConfiguration configuration)
configuration
- The application context configuration@NonNull public <T> ApplicationContext registerSingleton(@NonNull java.lang.Class<T> type, @NonNull T singleton, @Nullable Qualifier<T> qualifier, boolean inject)
BeanDefinitionRegistry
Registers a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by
invoking any PostConstruct
hooks.
If no bean definition data is found the bean is registered as is.
registerSingleton
in interface ApplicationContext
registerSingleton
in interface BeanContext
registerSingleton
in interface BeanDefinitionRegistry
registerSingleton
in class DefaultBeanContext
T
- The concrete typetype
- The bean typesingleton
- The singleton beanqualifier
- The bean qualifierinject
- Whether the singleton should be injected (defaults to true)@NonNull protected Environment createEnvironment(@NonNull ApplicationContextConfiguration configuration)
configuration
- The application context configuration@NonNull protected io.micronaut.core.convert.ConversionService createConversionService()
@NonNull public io.micronaut.core.convert.ConversionService<?> getConversionService()
getConversionService
in interface ApplicationContext
@NonNull public Environment getEnvironment()
getEnvironment
in interface ApplicationContext
@NonNull public ApplicationContext start()
DefaultBeanContext
start
in interface ApplicationContext
start
in interface LifeCycle<BeanContext>
start
in class DefaultBeanContext
@NonNull public ApplicationContext stop()
DefaultBeanContext
PreDestroy
hooks on loaded
singletons.stop
in interface ApplicationContext
stop
in interface LifeCycle<BeanContext>
stop
in class DefaultBeanContext
public boolean containsProperty(java.lang.String name)
containsProperty
in interface io.micronaut.core.value.PropertyResolver
public boolean containsProperties(java.lang.String name)
containsProperties
in interface io.micronaut.core.value.PropertyResolver
public <T> java.util.Optional<T> getProperty(java.lang.String name, io.micronaut.core.convert.ArgumentConversionContext<T> conversionContext)
getProperty
in interface io.micronaut.core.value.PropertyResolver
@NonNull public java.util.Collection<java.lang.String> getPropertyEntries(@NonNull java.lang.String name)
getPropertyEntries
in interface io.micronaut.core.value.PropertyResolver
@NonNull public java.util.Map<java.lang.String,java.lang.Object> getProperties(@Nullable java.lang.String name, @Nullable io.micronaut.core.naming.conventions.StringConvention keyFormat)
getProperties
in interface io.micronaut.core.value.PropertyResolver
protected void registerConfiguration(BeanConfiguration configuration)
DefaultBeanContext
registerConfiguration
in class DefaultBeanContext
configuration
- The configuration to registerprotected void startEnvironment()
protected void initializeContext(java.util.List<BeanDefinitionReference> contextScopeBeans, java.util.List<BeanDefinitionReference> processedBeans, java.util.List<BeanDefinitionReference> parallelBeans)
DefaultBeanContext
Context
scope beans.initializeContext
in class DefaultBeanContext
contextScopeBeans
- The context scope beansprocessedBeans
- The beans that require ExecutableMethodProcessor
handlingparallelBeans
- The parallel bean definitionsprotected <T> java.util.Collection<BeanDefinition<T>> findBeanCandidates(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, BeanDefinition<?> filter, boolean filterProxied)
DefaultBeanContext
findBeanCandidates
in class DefaultBeanContext
T
- The bean generic typeresolutionContext
- The current resolution contextbeanType
- The bean typefilter
- A bean definition to filter outfilterProxied
- Whether to filter out bean proxy targetsprotected <T> java.util.Collection<BeanDefinition<T>> findBeanCandidates(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, boolean filterProxied, java.util.function.Predicate<BeanDefinition<T>> predicate)
DefaultBeanContext
findBeanCandidates
in class DefaultBeanContext
T
- The bean generic typeresolutionContext
- The current resolution contextbeanType
- The bean typefilterProxied
- Whether to filter out bean proxy targetspredicate
- The predicate to filter candidatesprotected <T> java.util.Collection<BeanDefinition<T>> transformIterables(BeanResolutionContext resolutionContext, java.util.Collection<BeanDefinition<T>> candidates, boolean filterProxied)
DefaultBeanContext
transformIterables
in class DefaultBeanContext
T
- The bean typeresolutionContext
- The resolution contextcandidates
- The candidates.filterProxied
- Whether to filter proxied.protected <T> BeanDefinition<T> findConcreteCandidate(java.lang.Class<T> beanType, Qualifier<T> qualifier, java.util.Collection<BeanDefinition<T>> candidates)
DefaultBeanContext
findConcreteCandidate
in class DefaultBeanContext
T
- The generic timebeanType
- The bean typequalifier
- The qualifiercandidates
- The candidates, always more than 1public java.util.Optional<java.lang.String> resolvePlaceholders(java.lang.String str)
PropertyPlaceholderResolver
resolvePlaceholders
in interface PropertyPlaceholderResolver
str
- The placeholder to resolveOptional.empty()
if resolution was not possiblepublic java.lang.String resolveRequiredPlaceholders(java.lang.String str) throws ConfigurationException
PropertyPlaceholderResolver
resolveRequiredPlaceholders
in interface PropertyPlaceholderResolver
str
- The placeholder to resolveOptional.empty()
if resolution was not possibleConfigurationException
- If the placeholders could not be resolvedprotected void initializeTypeConverters(BeanContext beanContext)
beanContext
- The bean context