Class ApplicationContextBeanLookupUtils

java.lang.Object
org.springframework.grpc.internal.ApplicationContextBeanLookupUtils

public final class ApplicationContextBeanLookupUtils extends Object
Convenience methods performing bean lookups that are not currently provided by the standard Spring facilities.

NOTE: This is considered an internal non-public API despite its public method accessors.

Author:
Chris Bono
  • Method Details

    • getOrderedBeansWithAnnotation

      public static <B, A extends Annotation> LinkedHashMap<B,A> getOrderedBeansWithAnnotation(org.springframework.context.ApplicationContext applicationContext, Class<B> beanType, Class<A> annotationType)
      Find all beans of the given type which may be annotated with the supplied Annotation type and returns a map of matching bean instances with the annotation instance (or null if the bean is not annotated with the specified annotation type).

      Note that the map is ordered according to the matching beans Order annotation.

      Note that this method considers objects created by FactoryBeans, which means that FactoryBeans will get initialized in order to determine their object type.

      Type Parameters:
      B - type of bean
      A - type of annotation
      Parameters:
      applicationContext - the application context
      beanType - the type of bean
      annotationType - the type of annotation
      Returns:
      a map of matching bean instances with the annotation instance (or null) ordered according to their Order with annotation
    • getBeansWithAnnotation

      public static <B, A extends Annotation> List<B> getBeansWithAnnotation(org.springframework.context.ApplicationContext applicationContext, Class<B> beanType, Class<A> annotationType)
      Find all beans which are annotated with the supplied Annotation type.

      Note that this method considers objects created by FactoryBeans, which means that FactoryBeans will get initialized in order to determine their object type.

      Type Parameters:
      B - type of bean
      A - type of annotation
      Parameters:
      applicationContext - the application context
      beanType - the type of bean
      annotationType - the type of annotation
      Returns:
      a list of the matching beans ordered according to their Order annotation
    • sortBeansIncludingOrderAnnotation

      public static void sortBeansIncludingOrderAnnotation(org.springframework.context.ApplicationContext applicationContext, Class<?> beanType, List<?> beans)
      Sorts the supplied list in place using an OrderComparator that takes the @Order annotation on bean factory methods in configuration classes into account.
      Parameters:
      applicationContext - the application context
      beanType - the type of beans in the list
      beans - the list of beans to sort