BeanFactoryAnnotationUtils consistently applies bean name fallback when no BeanDefinition present

Issue: SPR-11915
master
Juergen Hoeller 10 years ago
parent 0451232eb4
commit f8b6114440
  1. 7
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,6 +34,7 @@ import org.springframework.util.ObjectUtils;
* Spring's {@link Qualifier @Qualifier} annotation. * Spring's {@link Qualifier @Qualifier} annotation.
* *
* @author Chris Beams * @author Chris Beams
* @author Juergen Hoeller
* @since 3.1.2 * @since 3.1.2
* @see BeanFactoryUtils * @see BeanFactoryUtils
*/ */
@ -90,6 +91,10 @@ public class BeanFactoryAnnotationUtils {
if (matchingBean != null) { if (matchingBean != null) {
return matchingBean; return matchingBean;
} }
else if (bf.containsBean(qualifier)) {
// Fallback: target bean at least found by bean name.
return bf.getBean(qualifier, beanType);
}
else { else {
throw new NoSuchBeanDefinitionException(qualifier, "No matching " + beanType.getSimpleName() + throw new NoSuchBeanDefinitionException(qualifier, "No matching " + beanType.getSimpleName() +
" bean found for qualifier '" + qualifier + "' - neither qualifier " + "match nor bean name match!"); " bean found for qualifier '" + qualifier + "' - neither qualifier " + "match nor bean name match!");

Loading…
Cancel
Save