24
24
25
25
import org .springframework .beans .SimpleTypeConverter ;
26
26
import org .springframework .beans .TypeConverter ;
27
+ import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
27
28
import org .springframework .beans .factory .config .BeanDefinitionHolder ;
28
29
import org .springframework .beans .factory .config .DependencyDescriptor ;
29
30
import org .springframework .beans .factory .support .AutowireCandidateQualifier ;
53
54
*/
54
55
public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwareAutowireCandidateResolver {
55
56
56
- private final Set <Class <? extends Annotation >> qualifierTypes = new LinkedHashSet <Class <? extends Annotation >>();
57
+ private final Set <Class <? extends Annotation >> qualifierTypes = new LinkedHashSet <Class <? extends Annotation >>(2 );
57
58
58
59
private Class <? extends Annotation > valueAnnotationType = Value .class ;
59
60
@@ -67,8 +68,8 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
67
68
public QualifierAnnotationAutowireCandidateResolver () {
68
69
this .qualifierTypes .add (Qualifier .class );
69
70
try {
70
- this .qualifierTypes .add ((Class <? extends Annotation >)
71
- ClassUtils . forName ( "javax.inject.Qualifier" , QualifierAnnotationAutowireCandidateResolver .class .getClassLoader ()));
71
+ this .qualifierTypes .add ((Class <? extends Annotation >) ClassUtils . forName ( "javax.inject.Qualifier" ,
72
+ QualifierAnnotationAutowireCandidateResolver .class .getClassLoader ()));
72
73
}
73
74
catch (ClassNotFoundException ex ) {
74
75
// JSR-330 API not available - simply skip.
@@ -233,9 +234,14 @@ protected boolean checkQualifier(
233
234
if (targetAnnotation == null ) {
234
235
// Look for matching annotation on the target class
235
236
if (getBeanFactory () != null ) {
236
- Class <?> beanType = getBeanFactory ().getType (bdHolder .getBeanName ());
237
- if (beanType != null ) {
238
- targetAnnotation = AnnotationUtils .getAnnotation (ClassUtils .getUserClass (beanType ), type );
237
+ try {
238
+ Class <?> beanType = getBeanFactory ().getType (bdHolder .getBeanName ());
239
+ if (beanType != null ) {
240
+ targetAnnotation = AnnotationUtils .getAnnotation (ClassUtils .getUserClass (beanType ), type );
241
+ }
242
+ }
243
+ catch (NoSuchBeanDefinitionException ex ) {
244
+ // Not the usual case - simply forget about the type check...
239
245
}
240
246
}
241
247
if (targetAnnotation == null && bd .hasBeanClass ()) {
0 commit comments