QualifierAnnotationAutowireCandidateResolver calls BeanFactory.getType defensively
Issue: SPR-12191
This commit is contained in:
@@ -24,6 +24,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.springframework.beans.SimpleTypeConverter;
|
import org.springframework.beans.SimpleTypeConverter;
|
||||||
import org.springframework.beans.TypeConverter;
|
import org.springframework.beans.TypeConverter;
|
||||||
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||||
import org.springframework.beans.factory.config.DependencyDescriptor;
|
import org.springframework.beans.factory.config.DependencyDescriptor;
|
||||||
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
||||||
@@ -53,7 +54,7 @@ import org.springframework.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwareAutowireCandidateResolver {
|
public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwareAutowireCandidateResolver {
|
||||||
|
|
||||||
private final Set<Class<? extends Annotation>> qualifierTypes = new LinkedHashSet<Class<? extends Annotation>>();
|
private final Set<Class<? extends Annotation>> qualifierTypes = new LinkedHashSet<Class<? extends Annotation>>(2);
|
||||||
|
|
||||||
private Class<? extends Annotation> valueAnnotationType = Value.class;
|
private Class<? extends Annotation> valueAnnotationType = Value.class;
|
||||||
|
|
||||||
@@ -67,8 +68,8 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
|||||||
public QualifierAnnotationAutowireCandidateResolver() {
|
public QualifierAnnotationAutowireCandidateResolver() {
|
||||||
this.qualifierTypes.add(Qualifier.class);
|
this.qualifierTypes.add(Qualifier.class);
|
||||||
try {
|
try {
|
||||||
this.qualifierTypes.add((Class<? extends Annotation>)
|
this.qualifierTypes.add((Class<? extends Annotation>) ClassUtils.forName("javax.inject.Qualifier",
|
||||||
ClassUtils.forName("javax.inject.Qualifier", QualifierAnnotationAutowireCandidateResolver.class.getClassLoader()));
|
QualifierAnnotationAutowireCandidateResolver.class.getClassLoader()));
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
// JSR-330 API not available - simply skip.
|
// JSR-330 API not available - simply skip.
|
||||||
@@ -233,9 +234,14 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
|||||||
if (targetAnnotation == null) {
|
if (targetAnnotation == null) {
|
||||||
// Look for matching annotation on the target class
|
// Look for matching annotation on the target class
|
||||||
if (getBeanFactory() != null) {
|
if (getBeanFactory() != null) {
|
||||||
Class<?> beanType = getBeanFactory().getType(bdHolder.getBeanName());
|
try {
|
||||||
if (beanType != null) {
|
Class<?> beanType = getBeanFactory().getType(bdHolder.getBeanName());
|
||||||
targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(beanType), type);
|
if (beanType != null) {
|
||||||
|
targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(beanType), type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
|
// Not the usual case - simply forget about the type check...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (targetAnnotation == null && bd.hasBeanClass()) {
|
if (targetAnnotation == null && bd.hasBeanClass()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user