Top Description Constructors Methods
org.springframework.beans.factory.annotation

public abstract Class BeanFactoryAnnotationUtils

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.LinkedHashMap, .Map, java.util.function.Predicate, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanFactory, .BeanFactoryUtils, .ListableBeanFactory, .NoSuchBeanDefinitionException, .NoUniqueBeanDefinitionException, org.springframework.beans.factory.config.BeanDefinition, .ConfigurableBeanFactory, org.springframework.beans.factory.support.AbstractBeanDefinition, .AutowireCandidateQualifier, .RootBeanDefinition, org.springframework.core.annotation.AnnotationUtils, org.springframework.lang.Nullable, org.springframework.util.Assert

Convenience methods performing bean lookups related to Spring-specific annotations, for example Spring's @Qualifier annotation.
Authors
Juergen Hoeller, Chris Beams
Since
3.1.2
See Also
BeanFactoryUtils

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

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)
isQualifierMatch
(Predicate<String>
the qualifier to match
qualifier
,
String
the name of the candidate bean
beanName
,
BeanFactory
the factory from which to retrieve the named bean
beanFactory
)

Check whether the named bean declares a qualifier of the given name.

public static <T> T

Returns:

the matching bean of type T (never null)
qualifiedBeanOfType
(BeanFactory
the factory to get the target bean from (also searching ancestors)
beanFactory
,
Class<T>
the type of bean to retrieve
beanType
,
String
the qualifier for selecting between multiple bean matches
qualifier
)

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.

private static <T> T

Returns:

the matching bean of type T (never null)
qualifiedBeanOfType
(ListableBeanFactory
the factory to get the target bean from
bf
,
Class<T>
the type of bean to retrieve
beanType
,
String
the qualifier for selecting between multiple bean matches
qualifier
)

Obtain a bean of type T from the given BeanFactory declaring a qualifier (e.g. <qualifier> or @Qualifier) matching the given qualifier).

public static <T> Map<String, T>

Returns:

the matching beans of type T
qualifiedBeansOfType
(ListableBeanFactory
the factory to get the target beans from (also searching ancestors)
beanFactory
,
Class<T>
the type of beans to retrieve
beanType
,
String
the qualifier for selecting among all type matches
qualifier
)

Retrieve all beans 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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BeanFactoryAnnotationUtilsback to summary
public BeanFactoryAnnotationUtils()

Method Detail

isQualifierMatchback to summary
public static boolean isQualifierMatch(Predicate<String> qualifier, String beanName, BeanFactory beanFactory)

Check whether the named bean declares a qualifier of the given name.

Parameters
qualifier:Predicate<String>

the qualifier to match

beanName:String

the name of the candidate bean

beanFactory:BeanFactory

the factory from which to retrieve the named bean

Returns:boolean

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
qualifiedBeanOfTypeback to summary
public static <T> T qualifiedBeanOfType(BeanFactory beanFactory, Class<T> beanType, 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:BeanFactory

the factory to get the target bean from (also searching ancestors)

beanType:Class<T>

the type of bean to retrieve

qualifier:String

the qualifier for selecting between multiple bean matches

Returns:T

the matching bean of type T (never null)

Exceptions
BeansException:
if the bean could not be created
NoUniqueBeanDefinitionException:
if multiple matching beans of type T found
NoSuchBeanDefinitionException:
if no matching bean of type T found
See Also
BeanFactoryUtils#beanOfTypeIncludingAncestors(ListableBeanFactory, Class)
qualifiedBeanOfTypeback to summary
private static <T> T qualifiedBeanOfType(ListableBeanFactory bf, Class<T> beanType, String qualifier)

Obtain a bean of type T from the given BeanFactory declaring a qualifier (e.g. <qualifier> or @Qualifier) matching the given qualifier).

Parameters
bf:ListableBeanFactory

the factory to get the target bean from

beanType:Class<T>

the type of bean to retrieve

qualifier:String

the qualifier for selecting between multiple bean matches

Returns:T

the matching bean of type T (never null)

qualifiedBeansOfTypeback to summary
public static <T> Map<String, T> qualifiedBeansOfType(ListableBeanFactory beanFactory, Class<T> beanType, String qualifier) throws BeansException

Retrieve all beans 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:ListableBeanFactory

the factory to get the target beans from (also searching ancestors)

beanType:Class<T>

the type of beans to retrieve

qualifier:String

the qualifier for selecting among all type matches

Returns:Map<String, T>

the matching beans of type T

Exceptions
BeansException:
if any of the matching beans could not be created
Since
5.1.1
See Also
BeanFactoryUtils#beansOfTypeIncludingAncestors(ListableBeanFactory, Class)