Class QualifierAnnotationAutowireCandidateResolver
- All Implemented Interfaces:
- Cloneable,- Aware,- BeanFactoryAware,- AutowireCandidateResolver
- Direct Known Subclasses:
- ContextAnnotationAutowireCandidateResolver
AutowireCandidateResolver implementation that matches bean definition qualifiers
 against qualifier annotations on the field or parameter to be autowired.
 Also supports suggested expression values through a value annotation.
 Also supports JSR-330's Qualifier annotation, if available.
- Since:
- 2.5
- Author:
- Mark Fisher, Juergen Hoeller, Stephane Nicoll
- See Also:
- 
Field SummaryFields inherited from class org.springframework.beans.factory.support.SimpleAutowireCandidateResolverINSTANCE
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new QualifierAnnotationAutowireCandidateResolver for Spring's standardQualifierannotation.QualifierAnnotationAutowireCandidateResolver(Class<? extends Annotation> qualifierType) Create a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation type.QualifierAnnotationAutowireCandidateResolver(Set<Class<? extends Annotation>> qualifierTypes) Create a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation types.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddQualifierType(Class<? extends Annotation> qualifierType) Register the given type to be used as a qualifier when autowiring.protected booleancheckQualifier(BeanDefinitionHolder bdHolder, Annotation annotation, TypeConverter typeConverter) Match the given qualifier annotation against the candidate bean definition.protected booleancheckQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) Match the given qualifier annotations against the candidate bean definition.protected ObjectExtract the value attribute from the given annotation.protected ObjectfindValue(Annotation[] annotationsToSearch) Determine a suggested value from any of the given candidate annotations.protected AnnotationgetFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) protected AnnotationgetQualifiedElementAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) getSuggestedValue(DependencyDescriptor descriptor) Determine whether the given dependency declares a value annotation.booleanhasQualifier(DependencyDescriptor descriptor) Determine whether the given dependency declares a qualifier annotation.booleanisAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) Determine whether the provided bean definition is an autowire candidate.protected booleanisQualifier(Class<? extends Annotation> annotationType) Checks whether the given annotation type is a recognized qualifier type.booleanisRequired(DependencyDescriptor descriptor) Determine whether the given dependency declares an autowired annotation, checking its required flag.voidsetValueAnnotationType(Class<? extends Annotation> valueAnnotationType) Set the 'value' annotation type, to be used on fields, method parameters and constructor parameters.Methods inherited from class org.springframework.beans.factory.support.GenericTypeAwareAutowireCandidateResolvercheckGenericTypeMatch, cloneIfNecessary, getBeanFactory, getResolvedDecoratedDefinition, getReturnTypeForFactoryMethod, setBeanFactoryMethods inherited from class org.springframework.beans.factory.support.SimpleAutowireCandidateResolvergetLazyResolutionProxyClass, getLazyResolutionProxyIfNecessary
- 
Constructor Details- 
QualifierAnnotationAutowireCandidateResolverpublic QualifierAnnotationAutowireCandidateResolver()
- 
QualifierAnnotationAutowireCandidateResolverCreate a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation type.- Parameters:
- qualifierType- the qualifier annotation to look for
 
- 
QualifierAnnotationAutowireCandidateResolverpublic QualifierAnnotationAutowireCandidateResolver(Set<Class<? extends Annotation>> qualifierTypes) Create a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation types.- Parameters:
- qualifierTypes- the qualifier annotations to look for
 
 
- 
- 
Method Details- 
addQualifierTypeRegister the given type to be used as a qualifier when autowiring.This identifies qualifier annotations for direct use (on fields, method parameters and constructor parameters) as well as meta annotations that in turn identify actual qualifier annotations. This implementation only supports annotations as qualifier types. The default is Spring's Qualifierannotation which serves as a qualifier for direct use and also as a meta annotation.- Parameters:
- qualifierType- the annotation type to register
 
- 
setValueAnnotationTypeSet the 'value' annotation type, to be used on fields, method parameters and constructor parameters.The default value annotation type is the Spring-provided Valueannotation.This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate a default value expression for a specific argument. 
- 
isAutowireCandidateDetermine whether the provided bean definition is an autowire candidate.To be considered a candidate the bean's autowire-candidate attribute must not have been set to 'false'. Also, if an annotation on the field or parameter to be autowired is recognized by this bean factory as a qualifier, the bean must 'match' against the annotation as well as any attributes it may contain. The bean definition must contain the same qualifier or match by meta attributes. A "value" attribute will fall back to match against the bean name or an alias if a qualifier or attribute does not match. - Specified by:
- isAutowireCandidatein interface- AutowireCandidateResolver
- Overrides:
- isAutowireCandidatein class- GenericTypeAwareAutowireCandidateResolver
- Parameters:
- bdHolder- the bean definition including bean name and aliases
- descriptor- the descriptor for the target method parameter or field
- Returns:
- whether the bean definition qualifies as autowire candidate
- See Also:
 
- 
checkQualifiersMatch the given qualifier annotations against the candidate bean definition.
- 
isQualifierChecks whether the given annotation type is a recognized qualifier type.
- 
checkQualifierprotected boolean checkQualifier(BeanDefinitionHolder bdHolder, Annotation annotation, TypeConverter typeConverter) Match the given qualifier annotation against the candidate bean definition.
- 
getQualifiedElementAnnotation@Nullable protected Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) 
- 
getFactoryMethodAnnotation@Nullable protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) 
- 
isRequiredDetermine whether the given dependency declares an autowired annotation, checking its required flag.- Specified by:
- isRequiredin interface- AutowireCandidateResolver
- Overrides:
- isRequiredin class- SimpleAutowireCandidateResolver
- Parameters:
- descriptor- the descriptor for the target method parameter or field
- Returns:
- whether the descriptor is marked as required or possibly indicating non-required status some other way (e.g. through a parameter annotation)
- See Also:
 
- 
hasQualifierDetermine whether the given dependency declares a qualifier annotation.- Specified by:
- hasQualifierin interface- AutowireCandidateResolver
- Overrides:
- hasQualifierin class- SimpleAutowireCandidateResolver
- Parameters:
- descriptor- the descriptor for the target method parameter or field
- Returns:
- whether the descriptor declares a qualifier, narrowing the candidate status beyond the type match
- See Also:
 
- 
getSuggestedValueDetermine whether the given dependency declares a value annotation.- Specified by:
- getSuggestedValuein interface- AutowireCandidateResolver
- Overrides:
- getSuggestedValuein class- SimpleAutowireCandidateResolver
- Parameters:
- descriptor- the descriptor for the target method parameter or field
- Returns:
- the value suggested (typically an expression String),
 or nullif none found
- See Also:
 
- 
findValueDetermine a suggested value from any of the given candidate annotations.
- 
extractValueExtract the value attribute from the given annotation.- Since:
- 4.3
 
 
-