Browse Source

QualifierAnnotationAutowireCandidateResolver calls BeanFactory.getType defensively

Issue: SPR-12191
pull/671/head
Juergen Hoeller 10 years ago
parent
commit
73ce3b514b
  1. 18
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java

18
spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java

@ -24,6 +24,7 @@ import java.util.Set; @@ -24,6 +24,7 @@ import java.util.Set;
import org.springframework.beans.SimpleTypeConverter;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
@ -53,7 +54,7 @@ import org.springframework.util.StringUtils; @@ -53,7 +54,7 @@ import org.springframework.util.StringUtils;
*/
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;
@ -67,8 +68,8 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa @@ -67,8 +68,8 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
public QualifierAnnotationAutowireCandidateResolver() {
this.qualifierTypes.add(Qualifier.class);
try {
this.qualifierTypes.add((Class<? extends Annotation>)
ClassUtils.forName("javax.inject.Qualifier", QualifierAnnotationAutowireCandidateResolver.class.getClassLoader()));
this.qualifierTypes.add((Class<? extends Annotation>) ClassUtils.forName("javax.inject.Qualifier",
QualifierAnnotationAutowireCandidateResolver.class.getClassLoader()));
}
catch (ClassNotFoundException ex) {
// JSR-330 API not available - simply skip.
@ -233,9 +234,14 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa @@ -233,9 +234,14 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
if (targetAnnotation == null) {
// Look for matching annotation on the target class
if (getBeanFactory() != null) {
Class<?> beanType = getBeanFactory().getType(bdHolder.getBeanName());
if (beanType != null) {
targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(beanType), type);
try {
Class<?> beanType = getBeanFactory().getType(bdHolder.getBeanName());
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()) {

Loading…
Cancel
Save