Interface BeanLocator

All Known Subinterfaces:
ApplicationContext, BeanContext, BeanResolutionContext, ConditionContext<T>, ConfigurableApplicationContext, ConfigurableBeanContext
All Known Implementing Classes:
AbstractBeanResolutionContext, DefaultBeanContext, DefaultBeanResolutionContext

public interface BeanLocator

Core interface for locating and discovering Bean instances.

Since:
1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> Optional<T>
    findBean(io.micronaut.core.type.Argument<T> beanType)
    Finds a Bean for the given type and qualifier.
    <T> Optional<T>
    findBean(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
    Finds a Bean for the given type and qualifier.
    default <T> Optional<T>
    findBean(Class<T> beanType)
    Finds a Bean for the given type.
    <T> Optional<T>
    findBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
    Finds a Bean for the given type and qualifier.
    default <T> Optional<T>
    Finds a Bean for the given type or attempts to instantiate the given instance.
    default <T> T
    getBean(io.micronaut.core.type.Argument<T> beanType)
    Obtains a Bean for the given type and qualifier.
    default <T> T
    getBean(io.micronaut.core.type.Argument<T> beanType, @Nullable 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.
    default <T> T
    getBean(Class<T> beanType)
    Obtains a Bean for the given type.
    <T> T
    getBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
    Obtains a Bean for the given type and qualifier.
    default <T> Collection<T>
    getBeansOfType(io.micronaut.core.type.Argument<T> beanType)
    Get all beans of the given type.
    default <T> Collection<T>
    getBeansOfType(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
    Get all beans of the given type.
    <T> Collection<T>
    getBeansOfType(Class<T> beanType)
    Get all beans of the given type.
    <T> Collection<T>
    getBeansOfType(Class<T> beanType, @Nullable Qualifier<T> qualifier)
    Get all beans of the given type.
    default <T> BeanProvider<T>
    getProvider(io.micronaut.core.type.Argument<T> beanType)
    Obtains a BeanProvider for the given type and qualifier.
    default <T> BeanProvider<T>
    getProvider(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
    Obtains a BeanProvider for the given type and qualifier.
    default <T> BeanProvider<T>
    getProvider(Class<T> beanType)
    Obtains a BeanProvider for the given type and qualifier.
    default <T> BeanProvider<T>
    getProvider(Class<T> beanType, @Nullable Qualifier<T> qualifier)
    Obtains a BeanProvider for the given type and qualifier.
    default <T> T
    getProxyTargetBean(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
    Resolves the proxy target for a given bean type.
    <T> T
    getProxyTargetBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
    Resolves the proxy target for a given bean type.
    default <V> Map<String,V>
    mapOfType(io.micronaut.core.type.Argument<V> beanType)
    Obtain a map of beans of the given type where the key is the qualifier.
    default <V> Map<String,V>
    mapOfType(io.micronaut.core.type.Argument<V> beanType, @Nullable Qualifier<V> qualifier)
    Obtain a map of beans of the given type where the key is the qualifier.
    default <V> Map<String,V>
    mapOfType(Class<V> beanType)
    Obtain a map of beans of the given type where the key is the qualifier.
    default <V> Map<String,V>
    mapOfType(Class<V> beanType, @Nullable Qualifier<V> qualifier)
    Obtain a map of beans of the given type where the key is the qualifier.
    default <T> Stream<T>
    streamOfType(io.micronaut.core.type.Argument<T> beanType)
    Obtain a stream of beans of the given type.
    default <T> Stream<T>
    streamOfType(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
    Obtain a stream of beans of the given type.
    default <T> Stream<T>
    streamOfType(Class<T> beanType)
    Obtain a stream of beans of the given type.
    <T> Stream<T>
    streamOfType(Class<T> beanType, @Nullable Qualifier<T> qualifier)
    Obtain a stream of beans of the given type.
  • Method Details

    • getBean

      <T> T getBean(BeanDefinition<T> definition)
      Obtains a Bean for the given bean definition.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      definition - The bean type
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      See Also:
    • getBean

      <T> T getBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Obtains a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      See Also:
    • getBean

      default <T> T getBean(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Obtains a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      Since:
      3.0.0
      See Also:
    • getBean

      default <T> T getBean(io.micronaut.core.type.Argument<T> beanType)
      Obtains a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      Since:
      3.0.0
      See Also:
    • getProvider

      default <T> BeanProvider<T> getProvider(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Obtains a BeanProvider for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The provider
      Since:
      4.5.0
      See Also:
    • getProvider

      default <T> BeanProvider<T> getProvider(Class<T> beanType)
      Obtains a BeanProvider for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      The provider
      Since:
      4.5.0
      See Also:
    • getProvider

      default <T> BeanProvider<T> getProvider(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Obtains a BeanProvider for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      The provider
      Since:
      4.5.0
      See Also:
    • getProvider

      default <T> BeanProvider<T> getProvider(io.micronaut.core.type.Argument<T> beanType)
      Obtains a BeanProvider for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      A provider for the given type
      Since:
      4.5.0
      See Also:
    • findBean

      <T> Optional<T> findBean(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Finds a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      Since:
      3.0.0
      See Also:
    • findBean

      default <T> Optional<T> findBean(io.micronaut.core.type.Argument<T> beanType)
      Finds a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      Since:
      3.0.0
      See Also:
    • findBean

      <T> Optional<T> findBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Finds a Bean for the given type and qualifier.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      See Also:
    • getBeansOfType

      <T> Collection<T> getBeansOfType(Class<T> beanType)
      Get all beans of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      The found beans
    • getBeansOfType

      <T> Collection<T> getBeansOfType(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Get all beans of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found beans
    • getBeansOfType

      default <T> Collection<T> getBeansOfType(io.micronaut.core.type.Argument<T> beanType)
      Get all beans of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      Returns:
      The found beans
      Since:
      3.0.0
    • getBeansOfType

      default <T> Collection<T> getBeansOfType(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Get all beans of the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      qualifier - The qualifier
      Returns:
      The found beans
      Since:
      3.0.0
    • streamOfType

      <T> Stream<T> streamOfType(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Obtain a stream of beans of the given type.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      See Also:
    • streamOfType

      default <T> Stream<T> streamOfType(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Obtain a stream of beans of the given type.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      Since:
      3.0.0
      See Also:
    • streamOfType

      default <T> Stream<T> streamOfType(io.micronaut.core.type.Argument<T> beanType)
      Obtain a stream of beans of the given type.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      A stream of instances
      Since:
      3.0.0
      See Also:
    • mapOfType

      default <V> Map<String,V> mapOfType(io.micronaut.core.type.Argument<V> beanType, @Nullable Qualifier<V> qualifier)
      Obtain a map of beans of the given type where the key is the qualifier.
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A map of instances
      Since:
      4.0.0
      See Also:
    • mapOfType

      default <V> Map<String,V> mapOfType(Class<V> beanType, @Nullable Qualifier<V> qualifier)
      Obtain a map of beans of the given type where the key is the qualifier.
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A map of instances
      Since:
      4.0.0
      See Also:
    • mapOfType

      default <V> Map<String,V> mapOfType(Class<V> beanType)
      Obtain a map of beans of the given type where the key is the qualifier.
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      A map of instances
      Since:
      4.0.0
      See Also:
    • mapOfType

      default <V> Map<String,V> mapOfType(io.micronaut.core.type.Argument<V> beanType)
      Obtain a map of beans of the given type where the key is the qualifier.
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      Returns:
      A map of instances
      Since:
      4.0.0
      See Also:
    • getProxyTargetBean

      <T> T getProxyTargetBean(Class<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:
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
    • getProxyTargetBean

      default <T> T getProxyTargetBean(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:
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
      Since:
      3.0.0
    • streamOfType

      default <T> Stream<T> streamOfType(Class<T> beanType)
      Obtain a stream of beans of the given type.
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The bean type
      Returns:
      A stream
    • getBean

      default <T> T getBean(Class<T> beanType)
      Obtains a Bean for the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      An instanceof said bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
      NoSuchBeanException - If the bean doesn't exist
    • findBean

      default <T> Optional<T> findBean(Class<T> beanType)
      Finds a Bean for the given type.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type
    • findOrInstantiateBean

      default <T> Optional<T> findOrInstantiateBean(Class<T> beanType)
      Finds a Bean for the given type or attempts to instantiate the given instance.
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      An instance of Optional that is either empty or containing the specified bean if it could not be found or instantiated
      Throws:
      NonUniqueBeanException - When multiple possible bean definitions exist for the given type