Package io.micronaut.context.beans
Interface BeanDefinitionService
- All Known Implementing Classes:
DefaultBeanDefinitionService
The API to access bean definitions and bean references.
Internal implementation is responsible for loading bean definitions and checking if it's enabled.
- Since:
- 5.0
- Author:
- Denis Stepanov
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddBeanDefinition(@NonNull RuntimeBeanDefinition<?> definition) Registers a runtime bean definition so it becomes visible to the provider alongside precompiled definitions.@io.micronaut.core.annotation.NonNull booleanReturns whether at least one bean definition exists for the given raw type.<B> @NonNull Iterable<BeanDefinition<B>>getBeanDefinitions(@NonNull BeanContext beanContext, @NonNull Argument<B> beanType, @Nullable Predicate<BeanDefinitionReference<B>> refPredicate, @Nullable Predicate<BeanDefinition<B>> defPredicate) Resolves enabled bean definitions.default @NonNull List<BeanDefinition<Object>>getBeanDefinitions(@NonNull BeanContext beanContext, @Nullable Predicate<BeanDefinition<Object>> defPredicate) Resolves enabled bean definitions.default @NonNull List<BeanDefinition<Object>>getBeanDefinitions(@NonNull BeanContext beanContext, @Nullable Predicate<BeanDefinitionReference<Object>> refPredicate, @Nullable Predicate<BeanDefinition<Object>> defPredicate) Resolves enabled bean definitions.<B> @NonNull Iterable<BeanDefinition<B>>getBeanDefinitions(@NonNull BeanResolutionContext beanResolutionContext, @NonNull Argument<B> beanType, @Nullable Predicate<BeanDefinitionReference<B>> refPredicate, @Nullable Predicate<BeanDefinition<B>> defPredicate) Resolves enabled bean definitions.Returns all bean references.getBeanReferences(@NonNull BeanContext beanContext) Returns all enabled bean references.List<DisabledBean<?>>getDisabledBeans(@NonNull BeanContext beanContext) Returns a disabled beans.getEagerInitBeans(@NonNull BeanContext beanContext) Returns bean definitions that should be initialized eagerly.getParallelBeans(@NonNull BeanContext beanContext) Returns bean definitions that are safe to be instantiated in parallel during startup.getProcessedBeans(@NonNull BeanContext beanContext) Returns bean definitions that require contextual processing during startup.getTargetProxyBeans(@NonNull BeanContext beanContext) Returns target proxy bean definitions.voidinitialize(BeanContext beanContext) Initializes the provider for use with the given context.voidregisterConfiguration(@NonNull BeanConfiguration configuration) Registers a bean configuration.voidremoveBeanDefinition(@NonNull RuntimeBeanDefinition<?> definition) Unregisters a runtime bean definition that was previously added.voidreset()Resets the provider by clearing internal caches and runtime registrations.voidtrackDisabled(QualifiedBeanType<?> beanType, List<String> reasons) Records that a qualified bean type has been disabled, along with human-readable reasons.
-
Method Details
-
addBeanDefinition
Registers a runtime bean definition so it becomes visible to the provider alongside precompiled definitions.- Parameters:
definition- the runtime definition to register, never null
-
removeBeanDefinition
Unregisters a runtime bean definition that was previously added.- Parameters:
definition- the runtime definition to remove, never null
-
trackDisabled
Records that a qualified bean type has been disabled, along with human-readable reasons.- Parameters:
beanType- the qualified bean type that has been disabledreasons- the reasons explaining why the bean is disabled
-
getEagerInitBeans
Returns bean definitions that should be initialized eagerly.- Parameters:
beanContext- the bean context to eliminate disabled beans- Returns:
- an iterable of bean definitions that should be eagerly instantiated
-
getProcessedBeans
Returns bean definitions that require contextual processing during startup.- Parameters:
beanContext- the bean context to eliminate disabled beans- Returns:
- an iterable of bean definitions that require processing at startup
-
getParallelBeans
Returns bean definitions that are safe to be instantiated in parallel during startup.- Parameters:
beanContext- the bean context to eliminate disabled beans- Returns:
- an iterable of bean definitions eligible for parallel creation
-
getTargetProxyBeans
Returns target proxy bean definitions.- Parameters:
beanContext- the bean context to eliminate disabled beans- Returns:
- an iterable of bean definitions that should be treated as target proxy candidates
-
getDisabledBeans
Returns a disabled beans.- Parameters:
beanContext- the bean context to eliminate disabled beans- Returns:
- a list of disabled beans with their associated reasons
-
exists
Returns whether at least one bean definition exists for the given raw type. This is a lightweight existence check and does not consider qualifiers.- Parameters:
beanType- the raw type to check- Returns:
- true if at least one definition of the given type is known; false otherwise
-
getBeanDefinitions
@NonNull default @NonNull List<BeanDefinition<Object>> getBeanDefinitions(@NonNull @NonNull BeanContext beanContext, @Nullable @Nullable Predicate<BeanDefinition<Object>> defPredicate) Resolves enabled bean definitions.- Parameters:
beanContext- the bean context to eliminate disabled beansdefPredicate- optional filter applied to definitions- Returns:
- a list of loaded bean definitions matching the filter
-
getBeanDefinitions
@NonNull default @NonNull List<BeanDefinition<Object>> getBeanDefinitions(@NonNull @NonNull BeanContext beanContext, @Nullable @Nullable Predicate<BeanDefinitionReference<Object>> refPredicate, @Nullable @Nullable Predicate<BeanDefinition<Object>> defPredicate) Resolves enabled bean definitions.- Parameters:
beanContext- the bean context to eliminate disabled beansrefPredicate- optional filter applied to referencesdefPredicate- optional filter applied to definitions- Returns:
- a list of loaded bean definitions matching the filters
-
getBeanDefinitions
@NonNull <B> @NonNull Iterable<BeanDefinition<B>> getBeanDefinitions(@NonNull @NonNull BeanContext beanContext, @NonNull @NonNull Argument<B> beanType, @Nullable @Nullable Predicate<BeanDefinitionReference<B>> refPredicate, @Nullable @Nullable Predicate<BeanDefinition<B>> defPredicate) Resolves enabled bean definitions.- Type Parameters:
B- the bean generic type- Parameters:
beanContext- the bean context to eliminate disabled beansbeanType- the bean type to resolverefPredicate- optional filter applied to referencesdefPredicate- optional filter applied to definitions- Returns:
- an iterable over matching bean definitions; iteration may trigger loading
-
getBeanDefinitions
@NonNull <B> @NonNull Iterable<BeanDefinition<B>> getBeanDefinitions(@NonNull @NonNull BeanResolutionContext beanResolutionContext, @NonNull @NonNull Argument<B> beanType, @Nullable @Nullable Predicate<BeanDefinitionReference<B>> refPredicate, @Nullable @Nullable Predicate<BeanDefinition<B>> defPredicate) Resolves enabled bean definitions.- Type Parameters:
B- the bean generic type- Parameters:
beanResolutionContext- the resolution context to eliminate disabled beansbeanType- the bean context to eliminate disabled beansrefPredicate- optional filter applied to references prior to loading; may be nulldefPredicate- optional filter applied to loaded definitions; may be null- Returns:
- an iterable over matching bean definitions]]
-
getBeanReferences
@NonNull @NonNull Iterable<BeanDefinitionReference<Object>> getBeanReferences(@NonNull @NonNull BeanContext beanContext) Returns all enabled bean references.- Parameters:
beanContext- the context for which references are requested- Returns:
- an iterable of bean definition references
-
getBeanReferences
Returns all bean references.- Returns:
- a list of all known bean definition references
-
registerConfiguration
Registers a bean configuration.- Parameters:
configuration- the configuration to register
-
reset
void reset()Resets the provider by clearing internal caches and runtime registrations. Intended for container lifecycle management and test scenarios. -
initialize
Initializes the provider for use with the given context. Implementations may perform warm-up and indexing.- Parameters:
beanContext- the bean context
-