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 Type
    Method
    Description
    <T> T
    bean(Class<T> requiredType)
    Return the bean instance that uniquely matches the given object type, if any.
    <T> T
    bean(String name, Class<T> requiredType)
    Return an instance, which may be shared or independent, of the specified bean.
    beanProvider(Class<T> requiredType)
    Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options.
    Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options.
  • Method Details

    • bean

      <T> T bean(Class<T> requiredType) throws BeansException
      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

      <T> T bean(String name, Class<T> requiredType) throws BeansException
      Return an instance, which may be shared or independent, of the specified bean.
      Parameters:
      name - the name of the bean to retrieve
      requiredType - type the bean must match; can be an interface or superclass
      Returns:
      an instance of the bean.
      Throws:
      BeansException
      See Also:
    • beanProvider

      <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.

      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

      <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. 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 is available with this variant.

      Parameters:
      requiredType - type the bean must match; can be a generic type declaration
      Returns:
      a corresponding provider handle
      See Also: