Class DefaultBeanContext
- java.lang.Object
-
- io.micronaut.context.DefaultBeanContext
-
- All Implemented Interfaces:
BeanContext
,BeanDefinitionRegistry
,BeanLocator
,ApplicationEventPublisher<java.lang.Object>
,ExecutionHandleLocator
,InitializableBeanContext
,LifeCycle<BeanContext>
,io.micronaut.core.annotation.AnnotationMetadataResolver
,io.micronaut.core.attr.AttributeHolder
,io.micronaut.core.attr.MutableAttributeHolder
,java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
DefaultApplicationContext
public class DefaultBeanContext extends java.lang.Object implements InitializableBeanContext
The default context implementations.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicBoolean
initializing
protected static org.slf4j.Logger
LOG
protected static org.slf4j.Logger
LOG_LIFECYCLE
protected java.util.concurrent.atomic.AtomicBoolean
running
protected java.util.concurrent.atomic.AtomicBoolean
terminating
-
Fields inherited from interface io.micronaut.context.event.ApplicationEventPublisher
NO_OP
-
Fields inherited from interface io.micronaut.context.ExecutionHandleLocator
EMPTY
-
-
Constructor Summary
Constructors Constructor Description DefaultBeanContext()
Construct a new bean context using the same classloader that loaded this DefaultBeanContext class.DefaultBeanContext(BeanContextConfiguration contextConfiguration)
Creates a new bean context with the given configuration.DefaultBeanContext(io.micronaut.core.io.scan.ClassPathResourceLoader resourceLoader)
Construct a new bean context with the given class loader.DefaultBeanContext(java.lang.ClassLoader classLoader)
Construct a new bean context with the given class loader.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> boolean
containsBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Return whether the bean of the given type is contained within this context.<T> boolean
containsBean(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Return whether the bean of the given type is contained within this context.protected <T> T
createBean(BeanResolutionContext resolutionContext, java.lang.Class<T> beanType, Qualifier<T> qualifier)
Creates a bean.<T> T
createBean(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Creates a new instance of the given bean performing dependency injection and returning a new instance.<T> T
createBean(java.lang.Class<T> beanType, Qualifier<T> qualifier, java.lang.Object... args)
Creates a new instance of the given bean performing dependency injection and returning a new instance.<T> T
createBean(java.lang.Class<T> beanType, Qualifier<T> qualifier, java.util.Map<java.lang.String,java.lang.Object> argumentValues)
Creates a new instance of the given bean performing dependency injection and returning a new instance.protected CustomScopeRegistry
createCustomScopeRegistry()
Allows customizing the custom scope registry.MethodExecutionHandle<?,java.lang.Object>
createExecutionHandle(BeanDefinition<? extends java.lang.Object> beanDefinition, ExecutableMethod<java.lang.Object,?> method)
Create an execution handle for the given bean definition and method.<T> void
destroyBean(BeanRegistration<T> registration)
Destroys the given bean.<T> T
destroyBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Destroys the bean for the given type causing it to be re-created.<T> T
destroyBean(java.lang.Class<T> beanType)
Destroys the bean for the given type causing it to be re-created.<T> T
destroyBean(T bean)
Destroys the given bean.protected <T> T
doCreateBean(BeanResolutionContext resolutionContext, BeanDefinition<T> beanDefinition, Qualifier<T> qualifier, boolean isSingleton, java.util.Map<java.lang.String,java.lang.Object> argumentValues)
Deprecated.protected <T> T
doCreateBean(BeanResolutionContext resolutionContext, BeanDefinition<T> beanDefinition, Qualifier<T> qualifier, io.micronaut.core.type.Argument<T> qualifierBeanType, boolean isSingleton, java.util.Map<java.lang.String,java.lang.Object> argumentValues)
Deprecated.protected <T> T
doCreateBean(BeanResolutionContext resolutionContext, BeanDefinition<T> definition, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier, java.lang.Object... args)
void
finalizeConfiguration()
Performs operations required before starting the application context, such as reading bean configurations.<T> java.util.Optional<T>
findBean(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Find an optional bean of the given type and qualifier.<T> java.util.Optional<T>
findBean(BeanResolutionContext resolutionContext, java.lang.Class<T> beanType, Qualifier<T> qualifier)
Find an optional bean of the given type and qualifier.<T> java.util.Optional<T>
findBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Finds a Bean for the given type and qualifier.<T> java.util.Optional<T>
findBean(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Finds a Bean for the given type and qualifier.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> 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(java.lang.Class<T> beanType, BeanDefinition<?> filter)
Find bean candidates for the given type.protected <T> java.util.Collection<BeanDefinition>
findBeanCandidatesForInstance(T instance)
Find bean candidates for the given type.java.util.Optional<BeanConfiguration>
findBeanConfiguration(java.lang.String configurationName)
Obtain a bean configuration by name.<T> java.util.Optional<BeanDefinition<T>>
findBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.<T> java.util.Optional<BeanDefinition<T>>
findBeanDefinition(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.<T> java.util.Optional<BeanRegistration<T>>
findBeanRegistration(T bean)
Obtain aBeanDefinition
for the given bean.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.<T,R>
java.util.Optional<ExecutableMethod<T,R>>findExecutableMethod(java.lang.Class<T> beanType, java.lang.String method, java.lang.Class[] arguments)
Finds an optimized execution handle for invoking a bean method.<T,R>
java.util.Optional<MethodExecutionHandle<T,R>>findExecutionHandle(java.lang.Class<T> beanType, Qualifier<?> qualifier, java.lang.String method, java.lang.Class... arguments)
Finds an optimized execution handle for invoking a bean method.<T,R>
java.util.Optional<MethodExecutionHandle<T,R>>findExecutionHandle(java.lang.Class<T> beanType, java.lang.String method, java.lang.Class... arguments)
Finds an optimized execution handle for invoking a bean method.<T,R>
java.util.Optional<MethodExecutionHandle<T,R>>findExecutionHandle(T bean, java.lang.String method, java.lang.Class[] arguments)
Finds an optimized execution handle for invoking a bean method.<T> java.util.Optional<BeanDefinition<T>>
findProxyBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain the proxyBeanDefinition
for the bean of type and qualifier.<T> java.util.Optional<BeanDefinition<T>>
findProxyBeanDefinition(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain the proxyBeanDefinition
for the bean of type and qualifier.<T> java.util.Optional<BeanDefinition<T>>
findProxyTargetBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.<T> java.util.Optional<BeanDefinition<T>>
findProxyTargetBeanDefinition(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.<T,R>
java.util.Optional<ExecutableMethod<T,R>>findProxyTargetMethod(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier, java.lang.String method, java.lang.Class... arguments)
Finds the original unproxied method for aProxyBeanDefinition
.<T,R>
java.util.Optional<ExecutableMethod<T,R>>findProxyTargetMethod(java.lang.Class<T> beanType, Qualifier<T> qualifier, java.lang.String method, java.lang.Class... arguments)
Finds the original unproxied method for aProxyBeanDefinition
.<T,R>
java.util.Optional<ExecutableMethod<T,R>>findProxyTargetMethod(java.lang.Class<T> beanType, java.lang.String method, java.lang.Class[] arguments)
Finds the original unproxied method for aProxyBeanDefinition
.protected <T> BeanRegistration<T>
getActiveBeanRegistration(BeanDefinition<T> beanDefinition, Qualifier qualifier)
Find an active singleton bean for the given definition and qualifier.java.util.Collection<BeanRegistration<?>>
getActiveBeanRegistrations(Qualifier<?> qualifier)
Find activeSingleton
beans for the given qualifier.<T> java.util.Collection<BeanRegistration<T>>
getActiveBeanRegistrations(java.lang.Class<T> beanType)
Find activeSingleton
beans for the given bean type.java.util.Collection<BeanDefinition<?>>
getAllBeanDefinitions()
Get all of the registeredBeanDefinition
.java.util.Optional<java.lang.Object>
getAttribute(java.lang.CharSequence name)
<T> java.util.Optional<T>
getAttribute(java.lang.CharSequence name, java.lang.Class<T> type)
io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object>
getAttributes()
<T> T
getBean(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Get a bean of the given type and qualifier.<T> T
getBean(BeanResolutionContext resolutionContext, BeanDefinition<T> beanDefinition, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Get a bean of the given bean definition, type and qualifier.<T> T
getBean(BeanResolutionContext resolutionContext, java.lang.Class<T> beanType)
Get a bean of the given type.<T> T
getBean(BeanResolutionContext resolutionContext, java.lang.Class<T> beanType, Qualifier<T> qualifier)
Get a bean of the given type and qualifier.<T> T
getBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtains a Bean for the given type and qualifier.<T> T
getBean(BeanDefinition<T> definition)
Obtains a Bean for the given bean definition.<T> T
getBean(java.lang.Class<T> beanType)
Obtains a Bean for the given type.<T> T
getBean(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtains a Bean for the given type and qualifier.<T> BeanDefinition<T>
getBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.java.util.Collection<BeanDefinitionReference<?>>
getBeanDefinitionReferences()
Get all of the enabledBeanDefinitionReference
.java.util.Collection<BeanDefinition<?>>
getBeanDefinitions(Qualifier<java.lang.Object> qualifier)
Get all of theBeanDefinition
for the given qualifier.<T> java.util.Collection<BeanDefinition<T>>
getBeanDefinitions(io.micronaut.core.type.Argument<T> beanType)
Obtain aBeanDefinition
for the given type.<T> java.util.Collection<BeanDefinition<T>>
getBeanDefinitions(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.<T> java.util.Collection<BeanDefinition<T>>
getBeanDefinitions(java.lang.Class<T> beanType)
Obtain aBeanDefinition
for the given type.<T> java.util.Collection<BeanDefinition<T>>
getBeanDefinitions(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.<T> BeanRegistration<T>
getBeanRegistration(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtains the bean registration for the given type and qualifier.<T> BeanRegistration<T>
getBeanRegistration(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Find a bean registration for the given bean type and optional qualifier.<T> BeanRegistration<T>
getBeanRegistration(BeanDefinition<T> beanDefinition)
Find a bean registration for the given bean definition.<T> BeanRegistration<T>
getBeanRegistration(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Find a bean registration for the given bean type and optional qualifier.<T> java.util.Collection<BeanRegistration<T>>
getBeanRegistrations(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtains the bean registrations for the given type and qualifier.<T> java.util.Collection<BeanRegistration<T>>
getBeanRegistrations(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations.<T> java.util.Collection<BeanRegistration<T>>
getBeanRegistrations(java.lang.Class<T> beanType)
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations.<T> java.util.Collection<BeanRegistration<T>>
getBeanRegistrations(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations.protected <T> java.util.Collection<T>
getBeansOfType(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType)
Get all beans of the given type.<T> java.util.Collection<T>
getBeansOfType(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Get all beans of the given type and qualifier.<T> java.util.Collection<T>
getBeansOfType(io.micronaut.core.type.Argument<T> beanType)
Get all beans of the given type.<T> java.util.Collection<T>
getBeansOfType(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Get all beans of the given type.<T> java.util.Collection<T>
getBeansOfType(java.lang.Class<T> beanType)
Get all beans of the given type.<T> java.util.Collection<T>
getBeansOfType(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Get all beans of the given type.BeanDefinitionValidator
getBeanValidator()
java.lang.ClassLoader
getClassLoader()
BeanContextConfiguration
getContextConfiguration()
Obtains the configuration for this context.<T> T
getProxyTargetBean(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Resolves the proxy target for a given bean type.<T> T
getProxyTargetBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Resolves the proxy target for a given bean type.<T> T
getProxyTargetBean(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Resolves the proxy target for a given bean type.protected void
initializeContext(java.util.List<BeanDefinitionReference> contextScopeBeans, java.util.List<BeanDefinitionReference> processedBeans, java.util.List<BeanDefinitionReference> parallelBeans)
Initialize the context with the givenContext
scope beans.protected void
initializeEventListeners()
Initialize the event listeners.protected <T> T
inject(BeanResolutionContext resolutionContext, BeanDefinition<?> requestingBeanDefinition, T instance)
Injects a bean.<T> T
inject(T instance)
Inject an existing instance.protected void
invalidateCaches()
Invalidates the bean caches.boolean
isRunning()
protected void
processParallelBeans(java.util.List<BeanDefinitionReference> parallelBeans)
Processes parallel bean definitions.void
publishEvent(java.lang.Object event)
Publish the given event.java.util.concurrent.Future<java.lang.Void>
publishEventAsync(java.lang.Object event)
Publish the given event.<T> void
refreshBean(BeanRegistration<T> beanRegistration)
Refresh the state of the given registered bean applying dependency injection and configuration wiring again.<T> java.util.Optional<T>
refreshBean(BeanIdentifier identifier)
Refresh the state of the given registered bean applying dependency injection and configuration wiring again.<B> BeanContext
registerBeanDefinition(RuntimeBeanDefinition<B> definition)
Registers a new reference at runtime.protected void
registerConfiguration(BeanConfiguration configuration)
Registers an active configuration.<T> BeanContext
registerSingleton(java.lang.Class<T> type, T singleton, Qualifier<T> qualifier, boolean inject)
Registers a new singleton bean at runtime.<T> java.util.Optional<T>
removeAttribute(java.lang.CharSequence name, java.lang.Class<T> type)
protected java.lang.Iterable<BeanConfiguration>
resolveBeanConfigurations()
Resolves theBeanConfiguration
class instances.protected java.util.List<BeanDefinitionReference>
resolveBeanDefinitionReferences()
Resolves theBeanDefinitionReference
class instances.protected java.util.List<BeanDefinitionReference>
resolveBeanDefinitionReferences(java.util.function.Predicate<BeanDefinitionReference> predicate)
Deprecated.io.micronaut.core.annotation.AnnotationMetadata
resolveMetadata(java.lang.Class<?> type)
BeanContext
setAttribute(java.lang.CharSequence name, java.lang.Object value)
BeanContext
start()
The start method will read all bean definition classes found on the classpath and initialize any pre-required state.BeanContext
stop()
The close method will shut down the context callingPreDestroy
hooks on loaded singletons.<T> java.util.stream.Stream<T>
streamOfType(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtains a stream of beans of the given type and qualifier.protected <T> java.util.stream.Stream<T>
streamOfType(BeanResolutionContext resolutionContext, java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtains a stream of beans of the given type and qualifier.<T> java.util.stream.Stream<T>
streamOfType(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain a stream of beans of the given type.<T> java.util.stream.Stream<T>
streamOfType(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain a stream of beans of the given type.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataResolver
resolveMetadata
-
Methods inherited from interface io.micronaut.context.BeanContext
createBean, createBean, createBean, destroyBean, getEventPublisher, registerSingleton, registerSingleton, registerSingleton, registerSingleton
-
Methods inherited from interface io.micronaut.context.BeanDefinitionRegistry
containsBean, containsBean, findBeanDefinition, findBeanDefinition, findProxyTargetBeanDefinition, getBeanDefinition, getBeanDefinition, getBeanDefinition, getProxyTargetBeanDefinition, getProxyTargetBeanDefinition
-
Methods inherited from interface io.micronaut.context.BeanLocator
findBean, findBean, findOrInstantiateBean, getBean, streamOfType, streamOfType
-
Methods inherited from interface io.micronaut.context.ExecutionHandleLocator
getExecutableMethod, getExecutionHandle, getExecutionHandle, getProxyTargetMethod, getProxyTargetMethod, getProxyTargetMethod
-
-
-
-
Field Detail
-
LOG
protected static final org.slf4j.Logger LOG
-
LOG_LIFECYCLE
protected static final org.slf4j.Logger LOG_LIFECYCLE
-
running
protected final java.util.concurrent.atomic.AtomicBoolean running
-
initializing
protected final java.util.concurrent.atomic.AtomicBoolean initializing
-
terminating
protected final java.util.concurrent.atomic.AtomicBoolean terminating
-
-
Constructor Detail
-
DefaultBeanContext
public DefaultBeanContext()
Construct a new bean context using the same classloader that loaded this DefaultBeanContext class.
-
DefaultBeanContext
public DefaultBeanContext(@NonNull java.lang.ClassLoader classLoader)
Construct a new bean context with the given class loader.- Parameters:
classLoader
- The class loader
-
DefaultBeanContext
public DefaultBeanContext(@NonNull io.micronaut.core.io.scan.ClassPathResourceLoader resourceLoader)
Construct a new bean context with the given class loader.- Parameters:
resourceLoader
- The resource loader
-
DefaultBeanContext
public DefaultBeanContext(@NonNull BeanContextConfiguration contextConfiguration)
Creates a new bean context with the given configuration.- Parameters:
contextConfiguration
- The context configuration
-
-
Method Detail
-
createCustomScopeRegistry
@NonNull protected CustomScopeRegistry createCustomScopeRegistry()
Allows customizing the custom scope registry.- Returns:
- The custom scope registry to use.
- Since:
- 3.0.0
-
isRunning
public boolean isRunning()
- Specified by:
isRunning
in interfaceLifeCycle<BeanContext>
- Returns:
- Whether the component is running
-
start
public BeanContext start()
The start method will read all bean definition classes found on the classpath and initialize any pre-required state.- Specified by:
start
in interfaceLifeCycle<BeanContext>
- Returns:
- This lifecycle component
-
stop
public BeanContext stop()
The close method will shut down the context callingPreDestroy
hooks on loaded singletons.- Specified by:
stop
in interfaceLifeCycle<BeanContext>
- Returns:
- This lifecycle component
-
resolveMetadata
@NonNull public io.micronaut.core.annotation.AnnotationMetadata resolveMetadata(java.lang.Class<?> type)
- Specified by:
resolveMetadata
in interfaceio.micronaut.core.annotation.AnnotationMetadataResolver
-
refreshBean
public <T> java.util.Optional<T> refreshBean(@Nullable BeanIdentifier identifier)
Description copied from interface:BeanContext
Refresh the state of the given registered bean applying dependency injection and configuration wiring again.
Note that if the bean was produced by a
Factory
then this method will refresh the factory too- Specified by:
refreshBean
in interfaceBeanContext
- Type Parameters:
T
- The concrete class- Parameters:
identifier
- TheBeanIdentifier
- Returns:
- An
Optional
of the instance if it exists for the given registration
-
refreshBean
public <T> void refreshBean(@NonNull BeanRegistration<T> beanRegistration)
Description copied from interface:BeanContext
Refresh the state of the given registered bean applying dependency injection and configuration wiring again.
Note that if the bean was produced by a
This methods skips an additional resolution of theFactory
then this method will refresh the factory tooBeanRegistration
.- Specified by:
refreshBean
in interfaceBeanContext
- Type Parameters:
T
- The concrete class- Parameters:
beanRegistration
- TheBeanRegistration
-
getActiveBeanRegistrations
public java.util.Collection<BeanRegistration<?>> getActiveBeanRegistrations(Qualifier<?> qualifier)
Description copied from interface:BeanDefinitionRegistry
Find activeSingleton
beans for the given qualifier. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Specified by:
getActiveBeanRegistrations
in interfaceBeanDefinitionRegistry
- Parameters:
qualifier
- The qualifier- Returns:
- The beans
-
getActiveBeanRegistrations
public <T> java.util.Collection<BeanRegistration<T>> getActiveBeanRegistrations(java.lang.Class<T> beanType)
Description copied from interface:BeanDefinitionRegistry
Find activeSingleton
beans for the given bean type. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Specified by:
getActiveBeanRegistrations
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean type- Returns:
- The beans
-
getBeanRegistrations
public <T> java.util.Collection<BeanRegistration<T>> getBeanRegistrations(java.lang.Class<T> beanType)
Description copied from interface:BeanDefinitionRegistry
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Specified by:
getBeanRegistrations
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean type- Returns:
- The beans
-
getBeanRegistration
public <T> BeanRegistration<T> getBeanRegistration(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Find a bean registration for the given bean type and optional qualifier.- Specified by:
getBeanRegistration
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The bean registration
-
getBeanRegistrations
public <T> java.util.Collection<BeanRegistration<T>> getBeanRegistrations(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Specified by:
getBeanRegistrations
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The beans
-
getBeanRegistrations
public <T> java.util.Collection<BeanRegistration<T>> getBeanRegistrations(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Specified by:
getBeanRegistrations
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The beans
-
getBeanRegistration
public <T> BeanRegistration<T> getBeanRegistration(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Find a bean registration for the given bean type and optional qualifier.- Specified by:
getBeanRegistration
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The potentially parameterized bean typequalifier
- The qualifier- Returns:
- The bean registration
-
getBeanRegistration
public <T> BeanRegistration<T> getBeanRegistration(BeanDefinition<T> beanDefinition)
Description copied from interface:BeanDefinitionRegistry
Find a bean registration for the given bean definition.- Specified by:
getBeanRegistration
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanDefinition
- The bean definition- Returns:
- The bean registration
-
findBeanRegistration
public <T> java.util.Optional<BeanRegistration<T>> findBeanRegistration(T bean)
Description copied from interface:BeanDefinitionRegistry
Obtain aBeanDefinition
for the given bean.- Specified by:
findBeanRegistration
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
bean
- The bean- Returns:
- An
Optional
of the bean definition
-
findExecutionHandle
public <T,R> java.util.Optional<MethodExecutionHandle<T,R>> findExecutionHandle(java.lang.Class<T> beanType, java.lang.String method, java.lang.Class... arguments)
Description copied from interface:ExecutionHandleLocator
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.- Specified by:
findExecutionHandle
in interfaceExecutionHandleLocator
- Type Parameters:
T
- The target beanR
- The result type of the execution handle- Parameters:
beanType
- The bean typemethod
- The methodarguments
- The arguments- Returns:
- The execution handle
-
createExecutionHandle
public MethodExecutionHandle<?,java.lang.Object> createExecutionHandle(BeanDefinition<? extends java.lang.Object> beanDefinition, ExecutableMethod<java.lang.Object,?> method)
Description copied from interface:ExecutionHandleLocator
Create an execution handle for the given bean definition and method.- Specified by:
createExecutionHandle
in interfaceExecutionHandleLocator
- Parameters:
beanDefinition
- The bean definitionmethod
- The method- Returns:
- The execution handle
-
findExecutionHandle
public <T,R> java.util.Optional<MethodExecutionHandle<T,R>> findExecutionHandle(java.lang.Class<T> beanType, Qualifier<?> qualifier, java.lang.String method, java.lang.Class... arguments)
Description copied from interface:ExecutionHandleLocator
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.- Specified by:
findExecutionHandle
in interfaceExecutionHandleLocator
- Type Parameters:
T
- The target beanR
- The result type of the execution handle- Parameters:
beanType
- The bean typequalifier
- The bean qualifermethod
- The methodarguments
- The arguments- Returns:
- The execution handle
-
findExecutableMethod
public <T,R> java.util.Optional<ExecutableMethod<T,R>> findExecutableMethod(java.lang.Class<T> beanType, java.lang.String method, java.lang.Class[] arguments)
Description copied from interface:ExecutionHandleLocator
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.- Specified by:
findExecutableMethod
in interfaceExecutionHandleLocator
- Type Parameters:
T
- The bean type classR
- The result type of the execution handle- Parameters:
beanType
- The bean typemethod
- The methodarguments
- The arguments- Returns:
- The execution handle
-
findExecutionHandle
public <T,R> java.util.Optional<MethodExecutionHandle<T,R>> findExecutionHandle(T bean, java.lang.String method, java.lang.Class[] arguments)
Description copied from interface:ExecutionHandleLocator
Finds an optimized execution handle for invoking a bean method. The execution handle may or may not be implemented by generated byte code.- Specified by:
findExecutionHandle
in interfaceExecutionHandleLocator
- Type Parameters:
T
- The target beanR
- The result type of the execution handle- Parameters:
bean
- The bean to invoke the method onmethod
- The methodarguments
- The arguments- Returns:
- The execution handle
-
registerSingleton
public <T> BeanContext registerSingleton(@NonNull java.lang.Class<T> type, @NonNull T singleton, Qualifier<T> qualifier, boolean inject)
Description copied from interface: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.
- Specified by:
registerSingleton
in interfaceBeanContext
- Specified by:
registerSingleton
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
type
- The bean typesingleton
- The singleton beanqualifier
- The bean qualifierinject
- Whether the singleton should be injected (defaults to true)- Returns:
- This bean context
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
- Specified by:
getClassLoader
in interfaceBeanContext
- Returns:
- The class loader used by this context
-
getBeanValidator
public BeanDefinitionValidator getBeanValidator()
- Specified by:
getBeanValidator
in interfaceBeanContext
- Returns:
- Get the configured bean validator, if any.
-
findBeanConfiguration
public java.util.Optional<BeanConfiguration> findBeanConfiguration(java.lang.String configurationName)
Description copied from interface:BeanDefinitionRegistry
Obtain a bean configuration by name.- Specified by:
findBeanConfiguration
in interfaceBeanDefinitionRegistry
- Parameters:
configurationName
- The configuration name- Returns:
- An optional with the configuration either present or not
-
getBeanDefinition
public <T> BeanDefinition<T> getBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Obtain aBeanDefinition
for the given type.- Specified by:
getBeanDefinition
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The potentially parameterized type typequalifier
- The qualifier- Returns:
- The
BeanDefinition
-
findBeanDefinition
public <T> java.util.Optional<BeanDefinition<T>> findBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Obtain aBeanDefinition
for the given type.- Specified by:
findBeanDefinition
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The potentially parameterized typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition
-
findBeanDefinition
public <T> java.util.Optional<BeanDefinition<T>> findBeanDefinition(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Obtain aBeanDefinition
for the given type.- Specified by:
findBeanDefinition
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition
-
getBeanDefinitions
public <T> java.util.Collection<BeanDefinition<T>> getBeanDefinitions(java.lang.Class<T> beanType)
Description copied from interface:BeanDefinitionRegistry
Obtain aBeanDefinition
for the given type.- Specified by:
getBeanDefinitions
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The type- Returns:
- An
Optional
of the bean definition
-
getBeanDefinitions
public <T> java.util.Collection<BeanDefinition<T>> getBeanDefinitions(io.micronaut.core.type.Argument<T> beanType)
Description copied from interface:BeanDefinitionRegistry
Obtain aBeanDefinition
for the given type.- Specified by:
getBeanDefinitions
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The type- Returns:
- An
Optional
of the bean definition
-
getBeanDefinitions
public <T> java.util.Collection<BeanDefinition<T>> getBeanDefinitions(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Obtain aBeanDefinition
for the given type.- Specified by:
getBeanDefinitions
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition
-
getBeanDefinitions
public <T> java.util.Collection<BeanDefinition<T>> getBeanDefinitions(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Obtain aBeanDefinition
for the given type.- Specified by:
getBeanDefinitions
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition
-
containsBean
public <T> boolean containsBean(@NonNull java.lang.Class<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Return whether the bean of the given type is contained within this context.- Specified by:
containsBean
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier for the bean- Returns:
- True if it is
-
containsBean
public <T> boolean containsBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Return whether the bean of the given type is contained within this context.- Specified by:
containsBean
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier for the bean- Returns:
- True if it is
-
getBean
@NonNull public <T> T getBean(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Obtains a Bean for the given type and qualifier.- Specified by:
getBean
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- An instanceof said bean
- See Also:
Qualifiers
-
getBean
@NonNull public <T> T getBean(@NonNull java.lang.Class<T> beanType)
Description copied from interface:BeanLocator
Obtains a Bean for the given type.- Specified by:
getBean
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean type- Returns:
- An instanceof said bean
-
getBean
@NonNull public <T> T getBean(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Obtains a Bean for the given type and qualifier.- Specified by:
getBean
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The potentially parameterized bean typequalifier
- The qualifier- Returns:
- An instanceof said bean
- See Also:
Qualifiers
-
findBean
public <T> java.util.Optional<T> findBean(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Finds a Bean for the given type and qualifier.- Specified by:
findBean
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- An instance of
Optional
that is either empty or containing the specified bean - See Also:
Qualifiers
-
findBean
public <T> java.util.Optional<T> findBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Finds a Bean for the given type and qualifier.- Specified by:
findBean
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- An instance of
Optional
that is either empty or containing the specified bean - See Also:
Qualifiers
-
getBeansOfType
public <T> java.util.Collection<T> getBeansOfType(java.lang.Class<T> beanType)
Description copied from interface:BeanLocator
Get all beans of the given type.- Specified by:
getBeansOfType
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean type- Returns:
- The found beans
-
getBeansOfType
public <T> java.util.Collection<T> getBeansOfType(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Get all beans of the given type.- Specified by:
getBeansOfType
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The found beans
-
getBeansOfType
public <T> java.util.Collection<T> getBeansOfType(io.micronaut.core.type.Argument<T> beanType)
Description copied from interface:BeanLocator
Get all beans of the given type.- Specified by:
getBeansOfType
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The potenitally parameterized bean type- Returns:
- The found beans
-
getBeansOfType
public <T> java.util.Collection<T> getBeansOfType(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Get all beans of the given type.- Specified by:
getBeansOfType
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The potenitally parameterized bean typequalifier
- The qualifier- Returns:
- The found beans
-
streamOfType
public <T> java.util.stream.Stream<T> streamOfType(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Obtain a stream of beans of the given type.- Specified by:
streamOfType
in interfaceBeanLocator
- Type Parameters:
T
- The bean concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- A stream of instances
- See Also:
Qualifiers
-
streamOfType
public <T> java.util.stream.Stream<T> streamOfType(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Obtain a stream of beans of the given type.- Specified by:
streamOfType
in interfaceBeanLocator
- Type Parameters:
T
- The bean concrete type- Parameters:
beanType
- The potentially parameterized bean typequalifier
- The qualifier- Returns:
- A stream of instances
- See Also:
Qualifiers
-
streamOfType
protected <T> java.util.stream.Stream<T> streamOfType(BeanResolutionContext resolutionContext, java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtains a stream of beans of the given type and qualifier.- Type Parameters:
T
- The bean concrete type- Parameters:
resolutionContext
- The bean resolution contextbeanType
- The bean typequalifier
- The qualifier- Returns:
- A stream
-
streamOfType
@Internal public <T> java.util.stream.Stream<T> streamOfType(BeanResolutionContext resolutionContext, io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtains a stream of beans of the given type and qualifier.- Type Parameters:
T
- The bean concrete type- Parameters:
resolutionContext
- The bean resolution contextbeanType
- The bean typequalifier
- The qualifier- Returns:
- A stream
-
inject
@NonNull public <T> T inject(@NonNull T instance)
Description copied from interface:BeanContext
Inject an existing instance.- Specified by:
inject
in interfaceBeanContext
- Type Parameters:
T
- The bean generic type- Parameters:
instance
- The instance to inject- Returns:
- The instance to inject
-
createBean
@NonNull public <T> T createBean(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanContext
Creates a new instance of the given bean performing dependency injection and returning a new instance.Note that the instance returned is not saved as a singleton in the context.
- Specified by:
createBean
in interfaceBeanContext
- Type Parameters:
T
- The bean generic type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The instance
-
createBean
@NonNull public <T> T createBean(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier, @Nullable java.util.Map<java.lang.String,java.lang.Object> argumentValues)
Description copied from interface:BeanContext
Creates a new instance of the given bean performing dependency injection and returning a new instance.
If the bean defines any
Parameter
values then the values passed in theargumentValues
parameter will be usedNote that the instance returned is not saved as a singleton in the context.
- Specified by:
createBean
in interfaceBeanContext
- Type Parameters:
T
- The bean generic type- Parameters:
beanType
- The bean typequalifier
- The qualifierargumentValues
- The argument values- Returns:
- The instance
-
createBean
@NonNull public <T> T createBean(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier, @Nullable java.lang.Object... args)
Description copied from interface:BeanContext
Creates a new instance of the given bean performing dependency injection and returning a new instance.
If the bean defines any
Parameter
values then the values passed in theargumentValues
parameter will be usedNote that the instance returned is not saved as a singleton in the context.
- Specified by:
createBean
in interfaceBeanContext
- Type Parameters:
T
- The bean generic type- Parameters:
beanType
- The bean typequalifier
- The qualifierargs
- The argument values- Returns:
- The instance
-
doCreateBean
@NonNull protected <T> T doCreateBean(@NonNull BeanResolutionContext resolutionContext, @NonNull BeanDefinition<T> definition, @NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier, @Nullable java.lang.Object... args)
- Type Parameters:
T
- the bean generic type- Parameters:
resolutionContext
- The bean resolution contextdefinition
- The bean definitionbeanType
- The bean typequalifier
- The qualifierargs
- The argument values- Returns:
- The instance
-
destroyBean
@Nullable public <T> T destroyBean(@NonNull io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Description copied from interface:BeanContext
Destroys the bean for the given type causing it to be re-created. If a singleton has been loaded it will be destroyed and removed from the context, otherwise null will be returned.- Specified by:
destroyBean
in interfaceBeanContext
- Type Parameters:
T
- The concrete class- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The destroy instance or null if no such bean exists
-
destroyBean
@NonNull public <T> T destroyBean(@NonNull T bean)
Description copied from interface:BeanContext
Destroys the given bean.- Specified by:
destroyBean
in interfaceBeanContext
- Type Parameters:
T
- The concrete class- Parameters:
bean
- The bean- Returns:
- The destroy instance
-
destroyBean
@Nullable public <T> T destroyBean(@NonNull java.lang.Class<T> beanType)
Description copied from interface:BeanContext
Destroys the bean for the given type causing it to be re-created. If a singleton has been loaded it will be destroyed and removed from the context, otherwise null will be returned.- Specified by:
destroyBean
in interfaceBeanContext
- Type Parameters:
T
- The concrete class- Parameters:
beanType
- The bean type- Returns:
- The destroy instance or null if no such bean exists
-
destroyBean
public <T> void destroyBean(@NonNull BeanRegistration<T> registration)
Description copied from interface:BeanContext
Destroys the given bean.- Specified by:
destroyBean
in interfaceBeanContext
- Type Parameters:
T
- The bean type- Parameters:
registration
- The bean registration
-
getActiveBeanRegistration
@Nullable protected <T> BeanRegistration<T> getActiveBeanRegistration(BeanDefinition<T> beanDefinition, Qualifier qualifier)
Find an active singleton bean for the given definition and qualifier.- Type Parameters:
T
- The bean generic type- Parameters:
beanDefinition
- The bean definitionqualifier
- The qualifier- Returns:
- The bean registration
-
createBean
@NonNull protected <T> T createBean(@Nullable BeanResolutionContext resolutionContext, @NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Creates a bean.- Type Parameters:
T
- The bean generic type- Parameters:
resolutionContext
- The bean resolution contextbeanType
- The bean typequalifier
- The qualifier- Returns:
- The instance
-
inject
@Internal @NonNull protected <T> T inject(@NonNull BeanResolutionContext resolutionContext, @Nullable BeanDefinition<?> requestingBeanDefinition, @NonNull T instance)
Injects a bean.- Type Parameters:
T
- The instance type- Parameters:
resolutionContext
- The bean resolution contextrequestingBeanDefinition
- The requesting bean definitioninstance
- The instance- Returns:
- The instance
-
getBeansOfType
@NonNull protected <T> java.util.Collection<T> getBeansOfType(@Nullable BeanResolutionContext resolutionContext, @NonNull io.micronaut.core.type.Argument<T> beanType)
Get all beans of the given type.- Type Parameters:
T
- The bean type parameter- Parameters:
resolutionContext
- The bean resolution contextbeanType
- The bean type- Returns:
- The found beans
-
getBeansOfType
@Internal @NonNull public <T> java.util.Collection<T> getBeansOfType(@Nullable BeanResolutionContext resolutionContext, @NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Get all beans of the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
resolutionContext
- The bean resolution contextbeanType
- The bean typequalifier
- The qualifier- Returns:
- The found beans
-
getProxyTargetBean
@NonNull public <T> T getProxyTargetBean(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.- Specified by:
getProxyTargetBean
in interfaceBeanLocator
- Type Parameters:
T
- The generic type- Parameters:
beanType
- The bean typequalifier
- The bean qualifier- Returns:
- The proxied instance
-
getProxyTargetBean
@NonNull public <T> T getProxyTargetBean(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanLocator
Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.- Specified by:
getProxyTargetBean
in interfaceBeanLocator
- Type Parameters:
T
- The generic type- Parameters:
beanType
- The bean typequalifier
- The bean qualifier- Returns:
- The proxied instance
-
getProxyTargetBean
@NonNull public <T> T getProxyTargetBean(@Nullable BeanResolutionContext resolutionContext, @NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.- Type Parameters:
T
- The generic type- Parameters:
resolutionContext
- The bean resolution contextbeanType
- The bean typequalifier
- The bean qualifier- Returns:
- The proxied instance
- Since:
- 3.1.0
-
findProxyTargetMethod
@NonNull public <T,R> java.util.Optional<ExecutableMethod<T,R>> findProxyTargetMethod(@NonNull java.lang.Class<T> beanType, @NonNull java.lang.String method, @NonNull java.lang.Class[] arguments)
Description copied from interface:ExecutionHandleLocator
Finds the original unproxied method for aProxyBeanDefinition
.- Specified by:
findProxyTargetMethod
in interfaceExecutionHandleLocator
- Type Parameters:
T
- The bean type classR
- The result type of the execution handle- Parameters:
beanType
- The bean typemethod
- The methodarguments
- The arguments- Returns:
- The execution handle
-
findProxyTargetMethod
@NonNull public <T,R> java.util.Optional<ExecutableMethod<T,R>> findProxyTargetMethod(@NonNull java.lang.Class<T> beanType, Qualifier<T> qualifier, @NonNull java.lang.String method, java.lang.Class... arguments)
Description copied from interface:ExecutionHandleLocator
Finds the original unproxied method for aProxyBeanDefinition
.- Specified by:
findProxyTargetMethod
in interfaceExecutionHandleLocator
- Type Parameters:
T
- The bean type classR
- The result type of the execution handle- Parameters:
beanType
- The bean typequalifier
- The qualifiermethod
- The methodarguments
- The arguments- Returns:
- The execution handle
-
findProxyTargetMethod
public <T,R> java.util.Optional<ExecutableMethod<T,R>> findProxyTargetMethod(@NonNull io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier, @NonNull java.lang.String method, java.lang.Class... arguments)
Description copied from interface:ExecutionHandleLocator
Finds the original unproxied method for aProxyBeanDefinition
.- Specified by:
findProxyTargetMethod
in interfaceExecutionHandleLocator
- Type Parameters:
T
- The bean type classR
- The result type of the execution handle- Parameters:
beanType
- The bean typequalifier
- The qualifiermethod
- The methodarguments
- The arguments- Returns:
- The execution handle
-
findProxyTargetBeanDefinition
@NonNull public <T> java.util.Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.- Specified by:
findProxyTargetBeanDefinition
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition
-
findProxyTargetBeanDefinition
public <T> java.util.Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.- Specified by:
findProxyTargetBeanDefinition
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition
-
getBeanDefinitions
@NonNull public java.util.Collection<BeanDefinition<?>> getBeanDefinitions(@Nullable Qualifier<java.lang.Object> qualifier)
Description copied from interface:BeanDefinitionRegistry
Get all of theBeanDefinition
for the given qualifier.- Specified by:
getBeanDefinitions
in interfaceBeanDefinitionRegistry
- Parameters:
qualifier
- The qualifier- Returns:
- The bean definitions
-
getAllBeanDefinitions
@NonNull public java.util.Collection<BeanDefinition<?>> getAllBeanDefinitions()
Description copied from interface:BeanDefinitionRegistry
Get all of the registeredBeanDefinition
.- Specified by:
getAllBeanDefinitions
in interfaceBeanDefinitionRegistry
- Returns:
- The bean definitions
-
getBeanDefinitionReferences
@NonNull public java.util.Collection<BeanDefinitionReference<?>> getBeanDefinitionReferences()
Description copied from interface:BeanDefinitionRegistry
Get all of the enabledBeanDefinitionReference
.- Specified by:
getBeanDefinitionReferences
in interfaceBeanDefinitionRegistry
- Returns:
- The bean definitions
-
registerBeanDefinition
@NonNull public <B> BeanContext registerBeanDefinition(@NonNull RuntimeBeanDefinition<B> definition)
Description copied from interface:BeanDefinitionRegistry
Registers a new reference at runtime. Not that registering beans can impact the object graph therefore should this should be done as soon as possible prior to the creation of other beans preferably with a high priorityContext
scope bean.- Specified by:
registerBeanDefinition
in interfaceBeanDefinitionRegistry
- Type Parameters:
B
- The bean type- Parameters:
definition
- The reference.- Returns:
- The registry
-
getBean
@NonNull public <T> T getBean(@Nullable BeanResolutionContext resolutionContext, @NonNull java.lang.Class<T> beanType)
Get a bean of the given type.- Type Parameters:
T
- The bean type parameter- Parameters:
resolutionContext
- The bean context resolutionbeanType
- The bean type- Returns:
- The found bean
-
getBean
@NonNull public <T> T getBean(@NonNull BeanDefinition<T> definition)
Description copied from interface:BeanLocator
Obtains a Bean for the given bean definition.- Specified by:
getBean
in interfaceBeanLocator
- Type Parameters:
T
- The bean type parameter- Parameters:
definition
- The bean type- Returns:
- An instanceof said bean
- See Also:
Qualifiers
-
getBean
@NonNull public <T> T getBean(@Nullable BeanResolutionContext resolutionContext, @NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Get a bean of the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
resolutionContext
- The bean context resolutionbeanType
- The bean typequalifier
- The qualifier- Returns:
- The found bean
-
getBean
@NonNull public <T> T getBean(@Nullable BeanResolutionContext resolutionContext, @NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Get a bean of the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
resolutionContext
- The bean context resolutionbeanType
- The bean typequalifier
- The qualifier- Returns:
- The found bean
- Since:
- 3.0.0
-
getBean
@Internal @NonNull public <T> T getBean(@Nullable BeanResolutionContext resolutionContext, @NonNull BeanDefinition<T> beanDefinition, @NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Get a bean of the given bean definition, type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
resolutionContext
- The bean context resolutionbeanDefinition
- The bean definitionbeanType
- The bean typequalifier
- The qualifier- Returns:
- The found bean
- Since:
- 3.5.0
-
findBean
@NonNull public <T> java.util.Optional<T> findBean(@Nullable BeanResolutionContext resolutionContext, @NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Find an optional bean of the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
resolutionContext
- The bean context resolutionbeanType
- The bean typequalifier
- The qualifier- Returns:
- The found bean wrapped as an
Optional
-
findBean
@Internal @NonNull public <T> java.util.Optional<T> findBean(@Nullable BeanResolutionContext resolutionContext, @NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Find an optional bean of the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
resolutionContext
- The bean context resolutionbeanType
- The bean typequalifier
- The qualifier- Returns:
- The found bean wrapped as an
Optional
- Since:
- 3.0.0
-
getContextConfiguration
public BeanContextConfiguration getContextConfiguration()
Description copied from interface:BeanContext
Obtains the configuration for this context.- Specified by:
getContextConfiguration
in interfaceBeanContext
- Returns:
- The
BeanContextConfiguration
-
publishEvent
public void publishEvent(@NonNull java.lang.Object event)
Description copied from interface:BeanContext
Publish the given event. The event will be published synchronously and only return once all listeners have consumed the event.- Specified by:
publishEvent
in interfaceApplicationEventPublisher<java.lang.Object>
- Specified by:
publishEvent
in interfaceBeanContext
- Parameters:
event
- The event to publish
-
publishEventAsync
@NonNull public java.util.concurrent.Future<java.lang.Void> publishEventAsync(@NonNull java.lang.Object event)
Description copied from interface:BeanContext
Publish the given event. The event will be published asynchronously. A future is returned that can be used to check whether the event completed successfully or not.- Specified by:
publishEventAsync
in interfaceApplicationEventPublisher<java.lang.Object>
- Specified by:
publishEventAsync
in interfaceBeanContext
- Parameters:
event
- The event to publish- Returns:
- A future that completes when the event is published
-
findProxyBeanDefinition
@NonNull public <T> java.util.Optional<BeanDefinition<T>> findProxyBeanDefinition(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Obtain the proxyBeanDefinition
for the bean of type and qualifier.- Specified by:
findProxyBeanDefinition
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition
-
findProxyBeanDefinition
@NonNull public <T> java.util.Optional<BeanDefinition<T>> findProxyBeanDefinition(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanDefinitionRegistry
Obtain the proxyBeanDefinition
for the bean of type and qualifier.- Specified by:
findProxyBeanDefinition
in interfaceBeanDefinitionRegistry
- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition
-
invalidateCaches
@Internal protected void invalidateCaches()
Invalidates the bean caches. For testing only.
-
resolveBeanDefinitionReferences
@NonNull protected java.util.List<BeanDefinitionReference> resolveBeanDefinitionReferences()
Resolves theBeanDefinitionReference
class instances. Default implementation uses ServiceLoader pattern.- Returns:
- The bean definition classes
-
resolveBeanDefinitionReferences
@NonNull @Deprecated protected java.util.List<BeanDefinitionReference> resolveBeanDefinitionReferences(@Nullable java.util.function.Predicate<BeanDefinitionReference> predicate)
Deprecated.Resolves theBeanDefinitionReference
class instances. Default implementation uses ServiceLoader pattern.- Parameters:
predicate
- The filter predicate, can be null- Returns:
- The bean definition classes
-
resolveBeanConfigurations
@NonNull protected java.lang.Iterable<BeanConfiguration> resolveBeanConfigurations()
Resolves theBeanConfiguration
class instances. Default implementation uses ServiceLoader pattern.- Returns:
- The bean definition classes
-
initializeEventListeners
protected void initializeEventListeners()
Initialize the event listeners.
-
initializeContext
protected void initializeContext(@NonNull java.util.List<BeanDefinitionReference> contextScopeBeans, @NonNull java.util.List<BeanDefinitionReference> processedBeans, @NonNull java.util.List<BeanDefinitionReference> parallelBeans)
Initialize the context with the givenContext
scope beans.- Parameters:
contextScopeBeans
- The context scope beansprocessedBeans
- The beans that requireExecutableMethodProcessor
handlingparallelBeans
- The parallel bean definitions
-
findBeanCandidates
@NonNull protected <T> java.util.Collection<BeanDefinition<T>> findBeanCandidates(@NonNull java.lang.Class<T> beanType, @Nullable BeanDefinition<?> filter)
Find bean candidates for the given type.- Type Parameters:
T
- The bean generic type- Parameters:
beanType
- The bean typefilter
- A bean definition to filter out- Returns:
- The candidates
-
findBeanCandidates
@NonNull protected <T> java.util.Collection<BeanDefinition<T>> findBeanCandidates(@Nullable BeanResolutionContext resolutionContext, @NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable BeanDefinition<?> filter, boolean filterProxied)
Find bean candidates for the given type.- Type Parameters:
T
- The bean generic type- Parameters:
resolutionContext
- The current resolution contextbeanType
- The bean typefilter
- A bean definition to filter outfilterProxied
- Whether to filter out bean proxy targets- Returns:
- The candidates
-
findBeanCandidates
@NonNull protected <T> java.util.Collection<BeanDefinition<T>> findBeanCandidates(@Nullable BeanResolutionContext resolutionContext, @NonNull io.micronaut.core.type.Argument<T> beanType, boolean filterProxied, java.util.function.Predicate<BeanDefinition<T>> predicate)
Find bean candidates for the given type.- Type Parameters:
T
- The bean generic type- Parameters:
resolutionContext
- The current resolution contextbeanType
- The bean typefilterProxied
- Whether to filter out bean proxy targetspredicate
- The predicate to filter candidates- Returns:
- The candidates
-
transformIterables
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.- Type Parameters:
T
- The bean type- Parameters:
resolutionContext
- The resolution contextcandidates
- The candidates.filterProxied
- Whether to filter proxied.- Returns:
- The candidates
-
findBeanCandidatesForInstance
@NonNull protected <T> java.util.Collection<BeanDefinition> findBeanCandidatesForInstance(@NonNull T instance)
Find bean candidates for the given type.- Type Parameters:
T
- The bean generic type- Parameters:
instance
- The bean instance- Returns:
- The candidates
-
registerConfiguration
protected void registerConfiguration(@NonNull BeanConfiguration configuration)
Registers an active configuration.- Parameters:
configuration
- The configuration to register
-
doCreateBean
@Internal @NonNull @Deprecated protected <T> T doCreateBean(@NonNull BeanResolutionContext resolutionContext, @NonNull BeanDefinition<T> beanDefinition, @Nullable Qualifier<T> qualifier, boolean isSingleton, @Nullable java.util.Map<java.lang.String,java.lang.Object> argumentValues)
Deprecated.Execution the creation of a bean. The returned value can be null if a factory method returned null.- Type Parameters:
T
- The bean generic type- Parameters:
resolutionContext
- TheBeanResolutionContext
beanDefinition
- TheBeanDefinition
qualifier
- TheQualifier
isSingleton
- Whether the bean is a singletonargumentValues
- Any argument values passed to create the bean- Returns:
- The created bean
-
doCreateBean
@Internal @NonNull @Deprecated protected <T> T doCreateBean(@NonNull BeanResolutionContext resolutionContext, @NonNull BeanDefinition<T> beanDefinition, @Nullable Qualifier<T> qualifier, @Nullable io.micronaut.core.type.Argument<T> qualifierBeanType, boolean isSingleton, @Nullable java.util.Map<java.lang.String,java.lang.Object> argumentValues)
Deprecated.Execution the creation of a bean. The returned value can be null if a factory method returned null.Method is deprecated since it doesn't do anything related to the singleton.
- Type Parameters:
T
- The bean generic type- Parameters:
resolutionContext
- TheBeanResolutionContext
beanDefinition
- TheBeanDefinition
qualifier
- TheQualifier
qualifierBeanType
- The bean type used in the qualifierisSingleton
- Whether the bean is a singletonargumentValues
- Any argument values passed to create the bean- Returns:
- The created bean
-
findConcreteCandidate
@NonNull protected <T> BeanDefinition<T> findConcreteCandidate(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier, @NonNull java.util.Collection<BeanDefinition<T>> candidates)
Fall back method to attempt to find a candidate for the given definitions.- Type Parameters:
T
- The generic time- Parameters:
beanType
- The bean typequalifier
- The qualifiercandidates
- The candidates, always more than 1- Returns:
- The concrete bean definition
-
processParallelBeans
protected void processParallelBeans(java.util.List<BeanDefinitionReference> parallelBeans)
Processes parallel bean definitions.- Parameters:
parallelBeans
- The parallel beans
-
getBeanRegistration
@Internal public <T> BeanRegistration<T> getBeanRegistration(@Nullable BeanResolutionContext resolutionContext, @NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Obtains the bean registration for the given type and qualifier.- Type Parameters:
T
- The generic type- Parameters:
resolutionContext
- The resolution contextbeanType
- The bean typequalifier
- The qualifier- Returns:
- A
BeanRegistration
-
getBeanRegistrations
@Internal public <T> java.util.Collection<BeanRegistration<T>> getBeanRegistrations(@Nullable BeanResolutionContext resolutionContext, @NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Obtains the bean registrations for the given type and qualifier.- Type Parameters:
T
- The generic type- Parameters:
resolutionContext
- The resolution contextbeanType
- The bean typequalifier
- The qualifier- Returns:
- A collection of
BeanRegistration
-
getAttributes
@NonNull public io.micronaut.core.convert.value.MutableConvertibleValues<java.lang.Object> getAttributes()
- Specified by:
getAttributes
in interfaceio.micronaut.core.attr.AttributeHolder
- Specified by:
getAttributes
in interfaceio.micronaut.core.attr.MutableAttributeHolder
-
getAttribute
@NonNull public java.util.Optional<java.lang.Object> getAttribute(java.lang.CharSequence name)
- Specified by:
getAttribute
in interfaceio.micronaut.core.attr.AttributeHolder
-
getAttribute
@NonNull public <T> java.util.Optional<T> getAttribute(java.lang.CharSequence name, java.lang.Class<T> type)
- Specified by:
getAttribute
in interfaceio.micronaut.core.attr.AttributeHolder
-
setAttribute
@NonNull public BeanContext setAttribute(@NonNull java.lang.CharSequence name, @Nullable java.lang.Object value)
- Specified by:
setAttribute
in interfaceio.micronaut.core.attr.MutableAttributeHolder
-
removeAttribute
@NonNull public <T> java.util.Optional<T> removeAttribute(@NonNull java.lang.CharSequence name, @NonNull java.lang.Class<T> type)
- Specified by:
removeAttribute
in interfaceio.micronaut.core.attr.MutableAttributeHolder
-
finalizeConfiguration
public void finalizeConfiguration()
Description copied from interface:InitializableBeanContext
Performs operations required before starting the application context, such as reading bean configurations.- Specified by:
finalizeConfiguration
in interfaceInitializableBeanContext
-
-