Interface BeanDefinitionRegistry
- All Known Subinterfaces:
ApplicationContext,BeanContext,ConfigurableApplicationContext,ConfigurableBeanContext
- All Known Implementing Classes:
DefaultBeanContext
Core bean definition registry interface containing methods to find BeanDefinition instances.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> booleancontainsBean(Argument<T> beanType) Return whether the bean of the given type is contained within this context.default <T> booleancontainsBean(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Return whether the bean of the given type is contained within this context.default booleancontainsBean(Class<?> beanType) Return whether the bean of the given type is contained within this context.<T> booleancontainsBean(Class<T> beanType, @Nullable Qualifier<T> qualifier) Return whether the bean of the given type is contained within this context.findBeanConfiguration(String configurationName) Obtain a bean configuration by name.default <T> Optional<BeanDefinition<T>> findBeanDefinition(Argument<T> beanType) Obtain aBeanDefinitionfor the given type.default <T> Optional<BeanDefinition<T>> findBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.default <T> Optional<BeanDefinition<T>> findBeanDefinition(Class<T> beanType) Obtain aBeanDefinitionfor the given type.<T> Optional<BeanDefinition<T>> findBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.default <T> Optional<BeanDefinition<T>> findBeanDefinition(T bean) Obtain aBeanDefinitionfor the given bean.<T> Optional<BeanRegistration<T>> findBeanRegistration(T bean) Obtain aBeanRegistrationfor the given bean.<T> Optional<BeanDefinition<T>> findProxyBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the proxyBeanDefinitionfor the bean of type and qualifier.default <T> Optional<BeanDefinition<T>> findProxyBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the proxyBeanDefinitionfor the bean of type and qualifier.default <T> Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.default <T> Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(BeanDefinition<T> proxyBeanDefinition) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.<T> Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.getActiveBeanRegistrations(Qualifier<?> qualifier) Find activeSingletonbeans for the given qualifier.<T> Collection<BeanRegistration<T>> getActiveBeanRegistrations(Class<T> beanType) Find activeSingletonbeans for the given bean type.Get all registeredBeanDefinition.default <T> BeanDefinition<T> getBeanDefinition(Argument<T> beanType) Obtain aBeanDefinitionfor the given type.default <T> BeanDefinition<T> getBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.default <T> BeanDefinition<T> getBeanDefinition(Class<T> beanType) Obtain aBeanDefinitionfor the given type.default <T> BeanDefinition<T> getBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.Get all enabledBeanDefinitionReference.getBeanDefinitions(Qualifier<Object> qualifier) Get all of theBeanDefinitionfor the given qualifier.default <T> Collection<BeanDefinition<T>> getBeanDefinitions(Argument<T> beanType) Obtain aBeanDefinitionfor the given type.default <T> Collection<BeanDefinition<T>> getBeanDefinitions(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.<T> Collection<BeanDefinition<T>> getBeanDefinitions(Class<T> beanType) Obtain aBeanDefinitionfor the given type.<T> Collection<BeanDefinition<T>> getBeanDefinitions(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.default <T> BeanRegistration<T> getBeanRegistration(Argument<T> beanType, @Nullable 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(Class<T> beanType, @Nullable Qualifier<T> qualifier) Find a bean registration for the given bean type and optional qualifier.default <T> Collection<BeanRegistration<T>> getBeanRegistrations(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Find and if necessary initializeSingletonbeans for the given bean type, returning all the active registrations.<T> Collection<BeanRegistration<T>> getBeanRegistrations(Class<T> beanType) Find and if necessary initializeSingletonbeans for the given bean type, returning all the active registrations.<T> Collection<BeanRegistration<T>> getBeanRegistrations(Class<T> beanType, @Nullable Qualifier<T> qualifier) Find and if necessary initializeSingletonbeans for the given bean type, returning all the active registrations.default Collection<DisabledBean<?>> Get all disabledDisabledBean.default <T> BeanDefinition<T> getProxyTargetBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.default <T> BeanDefinition<T> getProxyTargetBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.default BeanDefinitionRegistryregisterBeanConfiguration(BeanConfiguration configuration) Registers a bean configuration.default <B> BeanDefinitionRegistryregisterBeanDefinition(RuntimeBeanDefinition<B> definition) Registers a new reference at runtime.default <T> BeanDefinitionRegistryregisterSingleton(Class<T> type, T singleton) Deprecated, for removal: This API element is subject to removal in a future version.default <T> BeanDefinitionRegistryregisterSingleton(Class<T> type, T singleton, @Nullable Qualifier<T> qualifier) Deprecated, for removal: This API element is subject to removal in a future version.registerSingleton(Class<T> type, T singleton, @Nullable Qualifier<T> qualifier, boolean inject) Registers a new singleton bean at runtime.default BeanDefinitionRegistryregisterSingleton(Object singleton) Deprecated, for removal: This API element is subject to removal in a future version.default BeanDefinitionRegistryregisterSingleton(Object singleton, boolean inject) Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Details
-
containsBean
Return whether the bean of the given type is contained within this context.- Type Parameters:
T- The concrete type- Parameters:
beanType- The bean typequalifier- The qualifier for the bean- Returns:
- True if it is
-
containsBean
Return whether the bean of the given type is contained within this context.- Type Parameters:
T- The concrete type- Parameters:
beanType- The bean typequalifier- The qualifier for the bean- Returns:
- True if it is
- Since:
- 3.0.0
-
containsBean
Return whether the bean of the given type is contained within this context.- Type Parameters:
T- The concrete type- Parameters:
beanType- The bean type- Returns:
- True if it is
- Since:
- 3.0.0
-
registerBeanConfiguration
Registers a bean configuration. This allows disabling a set of beans based on a condition.- Parameters:
configuration- The configuration- Returns:
- The registry
- Since:
- 4.8.0
-
registerBeanDefinition
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 priorityContextscope bean.- Type Parameters:
B- The bean type- Parameters:
definition- The reference.- Returns:
- The registry
- Since:
- 3.6.0
-
registerSingleton
<T> BeanDefinitionRegistry registerSingleton(Class<T> type, T singleton, @Nullable Qualifier<T> qualifier, boolean inject) 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
PostConstructhooks.If no bean definition data is found the bean is registered as is.
- 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
-
findBeanConfiguration
Obtain a bean configuration by name.- Parameters:
configurationName- The configuration name- Returns:
- An optional with the configuration either present or not
-
findBeanDefinition
<T> Optional<BeanDefinition<T>> findBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
findBeanDefinition
default <T> Optional<BeanDefinition<T>> findBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The potentially parameterized typequalifier- The qualifier- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
-
findBeanDefinition
Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The potentially parameterized type- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
-
findBeanRegistration
Obtain aBeanRegistrationfor the given bean.- Type Parameters:
T- The concrete type- Parameters:
bean- The bean- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
findBeanDefinition
Obtain aBeanDefinitionfor the given bean.- Type Parameters:
T- The concrete type- Parameters:
bean- The bean- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type- Since:
- 4.3.0
-
getBeanDefinitions
Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The type- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
getBeanDefinitions
Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The type- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
-
getBeanDefinitions
<T> Collection<BeanDefinition<T>> getBeanDefinitions(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
getBeanDefinitions
default <T> Collection<BeanDefinition<T>> getBeanDefinitions(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
-
getBeanDefinitions
Get all of theBeanDefinitionfor the given qualifier.- Parameters:
qualifier- The qualifier- Returns:
- The bean definitions
-
getAllBeanDefinitions
Collection<BeanDefinition<Object>> getAllBeanDefinitions()Get all registeredBeanDefinition.- Returns:
- The bean definitions
-
getBeanDefinitionReferences
Collection<BeanDefinitionReference<Object>> getBeanDefinitionReferences()Get all enabledBeanDefinitionReference.- Returns:
- The bean definitions
-
getDisabledBeans
Get all disabledDisabledBean.- Returns:
- The disabled bean definitions
- Since:
- 4.0.0
-
getActiveBeanRegistrations
Find activeSingletonbeans 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.- Parameters:
qualifier- The qualifier- Returns:
- The beans
-
getActiveBeanRegistrations
Find activeSingletonbeans 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.- Type Parameters:
T- The concrete type- Parameters:
beanType- The bean type- Returns:
- The beans
-
getBeanRegistrations
Find and if necessary initializeSingletonbeans 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.- Type Parameters:
T- The concrete type- Parameters:
beanType- The bean type- Returns:
- The beans
-
getBeanRegistrations
<T> Collection<BeanRegistration<T>> getBeanRegistrations(Class<T> beanType, @Nullable Qualifier<T> qualifier) Find and if necessary initializeSingletonbeans 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.- Type Parameters:
T- The concrete type- Parameters:
beanType- The bean typequalifier- The qualifier- Returns:
- The beans
- Since:
- 2.4.0
-
getBeanRegistrations
default <T> Collection<BeanRegistration<T>> getBeanRegistrations(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Find and if necessary initializeSingletonbeans 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.- Type Parameters:
T- The concrete type- Parameters:
beanType- The bean typequalifier- The qualifier- Returns:
- The beans
- Since:
- 3.0.0
-
getBeanRegistration
Find a bean registration for the given bean type and optional qualifier.- Type Parameters:
T- The concrete type- Parameters:
beanType- The bean typequalifier- The qualifier- Returns:
- The bean registration
- Throws:
NoSuchBeanException- if the bean doesn't exist- Since:
- 2.4.0
-
getBeanRegistration
default <T> BeanRegistration<T> getBeanRegistration(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Find a bean registration for the given bean type and optional qualifier.- Type Parameters:
T- The concrete type- Parameters:
beanType- The potentially parameterized bean typequalifier- The qualifier- Returns:
- The bean registration
- Throws:
NoSuchBeanException- if the bean doesn't exist- Since:
- 3.0.0
-
getBeanRegistration
Find a bean registration for the given bean definition.- Type Parameters:
T- The concrete type- Parameters:
beanDefinition- The bean definition- Returns:
- The bean registration
- Throws:
NoSuchBeanException- if the bean doesn't exist- Since:
- 3.5.0
-
findProxyTargetBeanDefinition
<T> Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
findProxyTargetBeanDefinition
default <T> Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
findProxyTargetBeanDefinition
default <T> Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(BeanDefinition<T> proxyBeanDefinition) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.- Type Parameters:
T- The concrete type- Parameters:
proxyBeanDefinition- The proxy bean definition- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type- Since:
- 3.5.0
-
findProxyBeanDefinition
default <T> Optional<BeanDefinition<T>> findProxyBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the proxyBeanDefinitionfor the bean of type and qualifier.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
findProxyBeanDefinition
<T> Optional<BeanDefinition<T>> findProxyBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the proxyBeanDefinitionfor the bean of type and qualifier.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
registerSingleton
@Deprecated(forRemoval=true, since="5.0") default <T> BeanDefinitionRegistry registerSingleton(Class<T> type, T singleton, @Nullable Qualifier<T> qualifier) Deprecated, for removal: This API element is subject to removal in a future version.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
PostConstructhooks.If no bean definition data is found the bean is registered as is.
- Type Parameters:
T- The concrete type- Parameters:
type- The bean typesingleton- The singleton beanqualifier- The bean qualifier- Returns:
- This bean context
-
registerSingleton
@Deprecated(forRemoval=true, since="5.0") default <T> BeanDefinitionRegistry registerSingleton(Class<T> type, T singleton) Deprecated, for removal: This API element is subject to removal in a future version.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
PostConstructhooks.If no bean definition data is found the bean is registered as is.
- Type Parameters:
T- The concrete type- Parameters:
type- the bean typesingleton- The singleton bean- Returns:
- This bean context
-
registerSingleton
@Deprecated(forRemoval=true, since="5.0") default BeanDefinitionRegistry registerSingleton(Object singleton) Deprecated, for removal: This API element is subject to removal in a future version.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
PostConstructhooks.If no bean definition data is found the bean is registered as is.
- Parameters:
singleton- The singleton bean- Returns:
- This bean context
-
registerSingleton
@Deprecated(forRemoval=true, since="5.0") default BeanDefinitionRegistry registerSingleton(Object singleton, boolean inject) Deprecated, for removal: This API element is subject to removal in a future version.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
PostConstructhooks.If no bean definition data is found the bean is registered as is.
- Parameters:
singleton- The singleton beaninject- Whether the singleton should be injected (defaults to true)- Returns:
- This bean context
-
getBeanDefinition
default <T> BeanDefinition<T> getBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- The
BeanDefinition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given typeNoSuchBeanException- If the bean cannot be found
-
getBeanDefinition
default <T> BeanDefinition<T> getBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The potentially parameterized typequalifier- The qualifier- Returns:
- The
BeanDefinition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given typeNoSuchBeanException- If the bean cannot be found- Since:
- 3.0.
-
getProxyTargetBeanDefinition
default <T> BeanDefinition<T> getProxyTargetBeanDefinition(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- The
BeanDefinition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given typeNoSuchBeanException- If the bean cannot be found
-
getProxyTargetBeanDefinition
default <T> BeanDefinition<T> getProxyTargetBeanDefinition(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain the originalBeanDefinitionfor aProxyBeanDefinition.- Type Parameters:
T- The concrete type- Parameters:
beanType- The typequalifier- The qualifier- Returns:
- The
BeanDefinition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given typeNoSuchBeanException- If the bean cannot be found- Since:
- 3.0.0
-
getBeanDefinition
Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The type- Returns:
- The
BeanDefinition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given typeNoSuchBeanException- If the bean cannot be found
-
getBeanDefinition
Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The type- Returns:
- The
BeanDefinition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given typeNoSuchBeanException- If the bean cannot be found- Since:
- 3.0.0
-
findBeanDefinition
Obtain aBeanDefinitionfor the given type.- Type Parameters:
T- The concrete type- Parameters:
beanType- The type- Returns:
- An
Optionalof the bean definition - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
containsBean
Return whether the bean of the given type is contained within this context.- Parameters:
beanType- The bean type- Returns:
- True if it is
-
registerBeanDefinition(RuntimeBeanDefinition)