org.springframework.beans.factory.annotation

Class BeanFactoryAnnotationUtils

  • java.lang.Object
    • org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils


  • public abstract class BeanFactoryAnnotationUtils
    extends java.lang.Object
    Convenience methods performing bean lookups related to annotations, for example Spring's @Qualifier annotation.
    Since:
    3.1.2
    Author:
    Juergen Hoeller, Chris Beams
    See Also:
    BeanFactoryUtils
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static boolean isQualifierMatch(java.util.function.Predicate<java.lang.String> qualifier, java.lang.String beanName, BeanFactory beanFactory)
      Check whether the named bean declares a qualifier of the given name.
      static <T> T qualifiedBeanOfType(BeanFactory beanFactory, java.lang.Class<T> beanType, java.lang.String qualifier)
      Obtain a bean of type T from the given BeanFactory declaring a qualifier (e.g.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BeanFactoryAnnotationUtils

        public BeanFactoryAnnotationUtils()
    • Method Detail

      • qualifiedBeanOfType

        public static <T> T qualifiedBeanOfType(BeanFactory beanFactory,
                                                java.lang.Class<T> beanType,
                                                java.lang.String qualifier)
                                         throws BeansException
        Obtain a bean of type T from the given BeanFactory declaring a qualifier (e.g. via <qualifier> or @Qualifier) matching the given qualifier, or having a bean name matching the given qualifier.
        Parameters:
        beanFactory - the BeanFactory to get the target bean from
        beanType - the type of bean to retrieve
        qualifier - the qualifier for selecting between multiple bean matches
        Returns:
        the matching bean of type T (never null)
        Throws:
        NoUniqueBeanDefinitionException - if multiple matching beans of type T found
        NoSuchBeanDefinitionException - if no matching bean of type T found
        BeansException - if the bean could not be created
        See Also:
        BeanFactory.getBean(Class)
      • isQualifierMatch

        public static boolean isQualifierMatch(java.util.function.Predicate<java.lang.String> qualifier,
                                               java.lang.String beanName,
                                               @Nullable
                                               BeanFactory beanFactory)
        Check whether the named bean declares a qualifier of the given name.
        Parameters:
        qualifier - the qualifier to match
        beanName - the name of the candidate bean
        beanFactory - the BeanFactory from which to retrieve the named bean
        Returns:
        true if either the bean definition (in the XML case) or the bean's factory method (in the @Bean case) defines a matching qualifier value (through <qualifier> or @Qualifier)
        Since:
        5.0