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

public Class QualifierAnnotationAutowireCandidateResolver

extends GenericTypeAwareAutowireCandidateResolver
Class Inheritance
Imports
java.lang.annotation.Annotation, java.lang.reflect.AnnotatedElement, .Method, java.util.LinkedHashSet, .Map, .Set, org.springframework.beans.SimpleTypeConverter, .TypeConverter, org.springframework.beans.factory.BeanFactory, .NoSuchBeanDefinitionException, org.springframework.beans.factory.config.BeanDefinitionHolder, .DependencyDescriptor, org.springframework.beans.factory.support.AutowireCandidateQualifier, .AutowireCandidateResolver, .GenericTypeAwareAutowireCandidateResolver, .RootBeanDefinition, org.springframework.core.MethodParameter, org.springframework.core.annotation.AnnotatedElementUtils, .AnnotationAttributes, .AnnotationUtils, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ObjectUtils

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 jakarta.inject.Qualifier annotation, if available.

Authors
Mark Fisher, Juergen Hoeller, Stephane Nicoll
Since
2.5
See Also
AutowireCandidateQualifier, Qualifier, Value

Field Summary

Modifier and TypeField and Description
private final Set<Class<? extends Annotation>>
private Class<? extends Annotation>

Constructor Summary

AccessConstructor and Description
public
QualifierAnnotationAutowireCandidateResolver()

Create a new QualifierAnnotationAutowireCandidateResolver for Spring's standard Qualifier annotation.

public
QualifierAnnotationAutowireCandidateResolver(Class<? extends Annotation>
the qualifier annotation to look for
qualifierType
)

Create a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation type.

public
QualifierAnnotationAutowireCandidateResolver(Set<Class<? extends Annotation>>
the qualifier annotations to look for
qualifierTypes
)

Create a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation types.

Method Summary

Modifier and TypeMethod and Description
public void
addQualifierType(Class<? extends Annotation>
the annotation type to register
qualifierType
)

Register the given type to be used as a qualifier when autowiring.

protected boolean
checkQualifier(BeanDefinitionHolder bdHolder, Annotation annotation, TypeConverter typeConverter)

Match the given qualifier annotation against the candidate bean definition.

protected boolean
checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch)

Match the given qualifier annotations against the candidate bean definition.

protected Object
extractValue(AnnotationAttributes attr)

Extract the value attribute from the given annotation.

protected Object
findValue(Annotation[] annotationsToSearch)

Determine a suggested value from any of the given candidate annotations.

protected Annotation
protected Annotation
public Object
getSuggestedValue(DependencyDescriptor
the descriptor for the target method parameter or field
descriptor
)

Overrides org.springframework.beans.factory.support.SimpleAutowireCandidateResolver.getSuggestedValue.

Overrides default org.springframework.beans.factory.support.AutowireCandidateResolver.getSuggestedValue.

Determine whether the given dependency declares a value annotation.
public boolean
hasQualifier(DependencyDescriptor
the descriptor for the target method parameter or field
descriptor
)

Overrides org.springframework.beans.factory.support.SimpleAutowireCandidateResolver.hasQualifier.

Overrides default org.springframework.beans.factory.support.AutowireCandidateResolver.hasQualifier.

Determine whether the given dependency declares a qualifier annotation.
public boolean
isAutowireCandidate(BeanDefinitionHolder
the bean definition including bean name and aliases
bdHolder
,
DependencyDescriptor
the descriptor for the target method parameter or field
descriptor
)

Overrides org.springframework.beans.factory.support.GenericTypeAwareAutowireCandidateResolver.isAutowireCandidate.

Overrides default org.springframework.beans.factory.support.AutowireCandidateResolver.isAutowireCandidate.

Determine whether the provided bean definition is an autowire candidate.
protected boolean
isQualifier(Class<? extends Annotation> annotationType)

Checks whether the given annotation type is a recognized qualifier type.

public boolean
isRequired(DependencyDescriptor
the descriptor for the target method parameter or field
descriptor
)

Overrides org.springframework.beans.factory.support.SimpleAutowireCandidateResolver.isRequired.

Overrides default org.springframework.beans.factory.support.AutowireCandidateResolver.isRequired.

Determine whether the given dependency declares an autowired annotation, checking its required flag.
public void
setValueAnnotationType(Class<? extends Annotation> valueAnnotationType)

Set the 'value' annotation type, to be used on fields, method parameters and constructor parameters.

Inherited from org.springframework.beans.factory.support.GenericTypeAwareAutowireCandidateResolver:
checkGenericTypeMatchcloneIfNecessarygetBeanFactorygetResolvedDecoratedDefinitiongetReturnTypeForFactoryMethodsetBeanFactory

Field Detail

qualifierTypesback to summary
private final Set<Class<? extends Annotation>> qualifierTypes
valueAnnotationTypeback to summary
private Class<? extends Annotation> valueAnnotationType

Constructor Detail

QualifierAnnotationAutowireCandidateResolverback to summary
public QualifierAnnotationAutowireCandidateResolver()

Create a new QualifierAnnotationAutowireCandidateResolver for Spring's standard Qualifier annotation.

Also supports JSR-330's jakarta.inject.Qualifier annotation, if available.

Annotations
@SuppressWarnings:unchecked
QualifierAnnotationAutowireCandidateResolverback to summary
public QualifierAnnotationAutowireCandidateResolver(Class<? extends Annotation> qualifierType)

Create a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation type.

Parameters
qualifierType:Class<? extends Annotation>

the qualifier annotation to look for

QualifierAnnotationAutowireCandidateResolverback to summary
public QualifierAnnotationAutowireCandidateResolver(Set<Class<? extends Annotation>> qualifierTypes)

Create a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation types.

Parameters
qualifierTypes:Set<Class<? extends Annotation>>

the qualifier annotations to look for

Method Detail

addQualifierTypeback to summary
public void addQualifierType(Class<? extends Annotation> qualifierType)

Register 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 Qualifier annotation which serves as a qualifier for direct use and also as a meta annotation.

Parameters
qualifierType:Class<? extends Annotation>

the annotation type to register

checkQualifierback to summary
protected boolean checkQualifier(BeanDefinitionHolder bdHolder, Annotation annotation, TypeConverter typeConverter)

Match the given qualifier annotation against the candidate bean definition.

checkQualifiersback to summary
protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch)

Match the given qualifier annotations against the candidate bean definition.

extractValueback to summary
protected Object extractValue(AnnotationAttributes attr)

Extract the value attribute from the given annotation.

Since
4.3
findValueback to summary
protected Object findValue(Annotation[] annotationsToSearch)

Determine a suggested value from any of the given candidate annotations.

Annotations
@Nullable
getFactoryMethodAnnotationback to summary
protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type)
Annotations
@Nullable
getQualifiedElementAnnotationback to summary
protected Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type)
Annotations
@Nullable
getSuggestedValueback to summary
public Object getSuggestedValue(DependencyDescriptor descriptor)

Overrides org.springframework.beans.factory.support.SimpleAutowireCandidateResolver.getSuggestedValue.

Overrides default org.springframework.beans.factory.support.AutowireCandidateResolver.getSuggestedValue.

Determine whether the given dependency declares a value annotation.

Parameters
descriptor:DependencyDescriptor

Doc from org.springframework.beans.factory.support.AutowireCandidateResolver.getSuggestedValue.

the descriptor for the target method parameter or field

Returns:Object

Doc from org.springframework.beans.factory.support.AutowireCandidateResolver.getSuggestedValue.

the value suggested (typically an expression String), or null if none found

Annotations
@Override
@Nullable
See Also
Value
hasQualifierback to summary
public boolean hasQualifier(DependencyDescriptor descriptor)

Overrides org.springframework.beans.factory.support.SimpleAutowireCandidateResolver.hasQualifier.

Overrides default org.springframework.beans.factory.support.AutowireCandidateResolver.hasQualifier.

Determine whether the given dependency declares a qualifier annotation.

Parameters
descriptor:DependencyDescriptor

Doc from org.springframework.beans.factory.support.AutowireCandidateResolver.hasQualifier.

the descriptor for the target method parameter or field

Returns:boolean

Doc from org.springframework.beans.factory.support.AutowireCandidateResolver.hasQualifier.

whether the descriptor declares a qualifier, narrowing the candidate status beyond the type match

Annotations
@Override
See Also
isQualifier(Class), Qualifier
isAutowireCandidateback to summary
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor)

Overrides org.springframework.beans.factory.support.GenericTypeAwareAutowireCandidateResolver.isAutowireCandidate.

Overrides default org.springframework.beans.factory.support.AutowireCandidateResolver.isAutowireCandidate.

Determine 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.

Parameters
bdHolder:BeanDefinitionHolder

Doc from org.springframework.beans.factory.support.AutowireCandidateResolver.isAutowireCandidate.

the bean definition including bean name and aliases

descriptor:DependencyDescriptor

Doc from org.springframework.beans.factory.support.AutowireCandidateResolver.isAutowireCandidate.

the descriptor for the target method parameter or field

Returns:boolean

Doc from org.springframework.beans.factory.support.AutowireCandidateResolver.isAutowireCandidate.

whether the bean definition qualifies as autowire candidate

Annotations
@Override
See Also
Qualifier
isQualifierback to summary
protected boolean isQualifier(Class<? extends Annotation> annotationType)

Checks whether the given annotation type is a recognized qualifier type.

isRequiredback to summary
public boolean isRequired(DependencyDescriptor descriptor)

Overrides org.springframework.beans.factory.support.SimpleAutowireCandidateResolver.isRequired.

Overrides default org.springframework.beans.factory.support.AutowireCandidateResolver.isRequired.

Determine whether the given dependency declares an autowired annotation, checking its required flag.

Parameters
descriptor:DependencyDescriptor

Doc from org.springframework.beans.factory.support.AutowireCandidateResolver.isRequired.

the descriptor for the target method parameter or field

Returns:boolean

Doc from org.springframework.beans.factory.support.AutowireCandidateResolver.isRequired.

whether the descriptor is marked as required or possibly indicating non-required status some other way (e.g. through a parameter annotation)

Annotations
@Override
See Also
Autowired#required()
setValueAnnotationTypeback to summary
public void setValueAnnotationType(Class<? extends Annotation> valueAnnotationType)

Set the 'value' annotation type, to be used on fields, method parameters and constructor parameters.

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.