public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwareAutowireCandidateResolver
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.
AutowireCandidateQualifier
,
Qualifier
,
Value
Constructor and Description |
---|
QualifierAnnotationAutowireCandidateResolver()
Create a new QualifierAnnotationAutowireCandidateResolver
for Spring's standard
Qualifier annotation. |
QualifierAnnotationAutowireCandidateResolver(java.lang.Class<? extends java.lang.annotation.Annotation> qualifierType)
Create a new QualifierAnnotationAutowireCandidateResolver
for the given qualifier annotation type.
|
QualifierAnnotationAutowireCandidateResolver(java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> qualifierTypes)
Create a new QualifierAnnotationAutowireCandidateResolver
for the given qualifier annotation types.
|
Modifier and Type | Method and Description |
---|---|
void |
addQualifierType(java.lang.Class<? extends java.lang.annotation.Annotation> qualifierType)
Register the given type to be used as a qualifier when autowiring.
|
protected boolean |
checkQualifier(BeanDefinitionHolder bdHolder,
java.lang.annotation.Annotation annotation,
TypeConverter typeConverter)
Match the given qualifier annotation against the candidate bean definition.
|
protected boolean |
checkQualifiers(BeanDefinitionHolder bdHolder,
java.lang.annotation.Annotation[] annotationsToSearch)
Match the given qualifier annotations against the candidate bean definition.
|
protected java.lang.Object |
extractValue(AnnotationAttributes attr)
Extract the value attribute from the given annotation.
|
protected java.lang.Object |
findValue(java.lang.annotation.Annotation[] annotationsToSearch)
Determine a suggested value from any of the given candidate annotations.
|
protected java.lang.annotation.Annotation |
getFactoryMethodAnnotation(RootBeanDefinition bd,
java.lang.Class<? extends java.lang.annotation.Annotation> type) |
protected java.lang.annotation.Annotation |
getQualifiedElementAnnotation(RootBeanDefinition bd,
java.lang.Class<? extends java.lang.annotation.Annotation> type) |
java.lang.Object |
getSuggestedValue(DependencyDescriptor descriptor)
Determine whether the given dependency declares a value annotation.
|
boolean |
isAutowireCandidate(BeanDefinitionHolder bdHolder,
DependencyDescriptor descriptor)
Determine whether the provided bean definition is an autowire candidate.
|
protected boolean |
isQualifier(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Checks whether the given annotation type is a recognized qualifier type.
|
boolean |
isRequired(DependencyDescriptor descriptor)
Determine whether the given dependency declares an autowired annotation,
checking its required flag.
|
void |
setValueAnnotationType(java.lang.Class<? extends java.lang.annotation.Annotation> valueAnnotationType)
Set the 'value' annotation type, to be used on fields, method parameters
and constructor parameters.
|
checkGenericTypeMatch, getBeanFactory, getResolvedDecoratedDefinition, getReturnTypeForFactoryMethod, setBeanFactory
getLazyResolutionProxyIfNecessary
public QualifierAnnotationAutowireCandidateResolver()
public QualifierAnnotationAutowireCandidateResolver(java.lang.Class<? extends java.lang.annotation.Annotation> qualifierType)
qualifierType
- the qualifier annotation to look forpublic QualifierAnnotationAutowireCandidateResolver(java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> qualifierTypes)
qualifierTypes
- the qualifier annotations to look forpublic void addQualifierType(java.lang.Class<? extends java.lang.annotation.Annotation> qualifierType)
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 Qualifier
annotation which serves
as a qualifier for direct use and also as a meta annotation.
qualifierType
- the annotation type to registerpublic void setValueAnnotationType(java.lang.Class<? extends java.lang.annotation.Annotation> valueAnnotationType)
The default value annotation type is the Spring-provided
Value
annotation.
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.
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor)
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 fallback to match against the bean name or an alias if a qualifier or attribute does not match.
isAutowireCandidate
in interface AutowireCandidateResolver
isAutowireCandidate
in class GenericTypeAwareAutowireCandidateResolver
bdHolder
- the bean definition including bean name and aliasesdescriptor
- the descriptor for the target method parameter or fieldQualifier
protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, java.lang.annotation.Annotation[] annotationsToSearch)
protected boolean isQualifier(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
protected boolean checkQualifier(BeanDefinitionHolder bdHolder, java.lang.annotation.Annotation annotation, TypeConverter typeConverter)
@Nullable protected java.lang.annotation.Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, java.lang.Class<? extends java.lang.annotation.Annotation> type)
@Nullable protected java.lang.annotation.Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, java.lang.Class<? extends java.lang.annotation.Annotation> type)
public boolean isRequired(DependencyDescriptor descriptor)
isRequired
in interface AutowireCandidateResolver
isRequired
in class SimpleAutowireCandidateResolver
descriptor
- the descriptor for the target method parameter or fieldAutowired.required()
@Nullable public java.lang.Object getSuggestedValue(DependencyDescriptor descriptor)
getSuggestedValue
in interface AutowireCandidateResolver
getSuggestedValue
in class SimpleAutowireCandidateResolver
descriptor
- the descriptor for the target method parameter or fieldnull
if none foundValue
@Nullable protected java.lang.Object findValue(java.lang.annotation.Annotation[] annotationsToSearch)
protected java.lang.Object extractValue(AnnotationAttributes attr)