Interface BeanRegistry.SupplierContext
- Enclosing interface:
- BeanRegistry
public static interface BeanRegistry.SupplierContext
Context available from the bean instance supplier designed to give access
to bean dependencies.
-
Method Summary
Modifier and TypeMethodDescription<T> T
Return the bean instance that uniquely matches the given object type, if any.<T> T
Return an instance, which may be shared or independent, of the specified bean.<T> ObjectProvider<T>
beanProvider
(Class<T> requiredType) Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options.<T> ObjectProvider<T>
beanProvider
(ResolvableType requiredType) Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options.
-
Method Details
-
bean
Return the bean instance that uniquely matches the given object type, if any.- Parameters:
requiredType
- type the bean must match; can be an interface or superclass- Returns:
- an instance of the single bean matching the required type
- Throws:
BeansException
- See Also:
-
bean
Return an instance, which may be shared or independent, of the specified bean.- Parameters:
name
- the name of the bean to retrieverequiredType
- type the bean must match; can be an interface or superclass- Returns:
- an instance of the bean.
- Throws:
BeansException
- See Also:
-
beanProvider
Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options.For matching a generic type, consider
beanProvider(ResolvableType)
.- Parameters:
requiredType
- type the bean must match; can be an interface or superclass- Returns:
- a corresponding provider handle
- See Also:
-
beanProvider
Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options. This variant allows for specifying a generic type to match, similar to reflective injection points with generic type declarations in method/constructor parameters.Note that collections of beans are not supported here, in contrast to reflective injection points. For programmatically retrieving a list of beans matching a specific type, specify the actual bean type as an argument here and subsequently use
ObjectProvider.orderedStream()
or its lazy streaming/iteration options.Also, generics matching is strict here, as per the Java assignment rules. For lenient fallback matching with unchecked semantics (similar to the 'unchecked' Java compiler warning), consider calling
beanProvider(Class)
with the raw type as a second step if no full generic match isavailable
with this variant.- Parameters:
requiredType
- type the bean must match; can be a generic type declaration- Returns:
- a corresponding provider handle
- See Also:
-