From f8b611444072bea0a2755ba73b4dd15fe33098e5 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 1 Jul 2014 16:29:40 +0200 Subject: [PATCH] BeanFactoryAnnotationUtils consistently applies bean name fallback when no BeanDefinition present Issue: SPR-11915 --- .../factory/annotation/BeanFactoryAnnotationUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java index 5b604fd263..a3f8791a55 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java +++ b/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"); * 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. * * @author Chris Beams + * @author Juergen Hoeller * @since 3.1.2 * @see BeanFactoryUtils */ @@ -90,6 +91,10 @@ public class BeanFactoryAnnotationUtils { if (matchingBean != null) { return matchingBean; } + else if (bf.containsBean(qualifier)) { + // Fallback: target bean at least found by bean name. + return bf.getBean(qualifier, beanType); + } else { throw new NoSuchBeanDefinitionException(qualifier, "No matching " + beanType.getSimpleName() + " bean found for qualifier '" + qualifier + "' - neither qualifier " + "match nor bean name match!");