Skip to content

BeanFactoryAnnotationUtils.qualifiedBeanOfType does not work for @Qualifier on bean class [SPR-13819] #18392

@spring-projects-issues

Description

@spring-projects-issues

Emilien Guenichon opened SPR-13819 and commented

The BeanFactoryAnnotationUtils.qualifiedBeanOfType method doesn't match the qualified bean even with the good qualifier given and interface.

As you can see from the StackOverflow link.
And from an execution of the attached project.

QualifiedInterface processor = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
beanFactory, QualifiedInterface.class, "QualifierA");

System.out.println("The selected processor should be A " + processor);

An interface QualifiedInterface.java

public interface QualifiedInterface {

}
Two beans QualifiedA.java

@Component
@Qualifier("QualifierA")
public class QualifiedA implements QualifiedInterface {

@Override
public String toString() {
    return "QualifiedA";
}

}

and QualifiedB.java :

@Component
@Qualifier("QualifierB")
public class QualifiedB implements QualifiedInterface {

@Override
public String toString() {
    return "QualifiedB";
}

}

Here a log of the execution (care about qualifier names and case as I tried to lower them between the stackoverflow tickets and this JIRA)

2015-12-24 16:14:50.445 INFO 9852 --- [ main] b.sample.Application : Starting Application on DTBE-DEV4 with PID 9852 (D:\Workspace_netbeans\BeanFactoryAnnotationUtilsProblem\target\classes started by eguenichon in D:\Workspace_netbeans\BeanFactoryAnnotationUtilsProblem)
2015-12-24 16:14:50.449 INFO 9852 --- [ main] b.sample.Application : No active profile set, falling back to default profiles: default
2015-12-24 16:14:50.535 INFO 9852 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5390ecf8: startup date [Thu Dec 24 16:14:50 CET 2015]; root of context hierarchy
2015-12-24 16:14:53.251 INFO 9852 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2015-12-24 16:14:53.266 INFO 9852 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2015-12-24 16:14:53.485 INFO 9852 --- [ main] b.sample.Application : Started Application in 3.662 seconds (JVM running for 4.154)
Existing qualified beans ...
qualifiera

  • @org.springframework.stereotype.Component(value=)
  • @org.springframework.beans.factory.annotation.Qualifier(value=qualifiera)
    qualifierb
  • @org.springframework.stereotype.Component(value=)
  • @org.springframework.beans.factory.annotation.Qualifier(value=qualifierb)
    Existing qualified beans from context ...
    qualifiera
  • @org.springframework.stereotype.Component(value=)
  • @org.springframework.beans.factory.annotation.Qualifier(value=qualifiera)
    qualifierb
  • @org.springframework.stereotype.Component(value=)
  • @org.springframework.beans.factory.annotation.Qualifier(value=qualifierb)
    Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'qualifiera' is defined: No matching QualifiedInterface bean found for qualifier 'qualifiera' - neither qualifier match nor bean name match!
    at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:98)
    at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:55)
    at beanfactoryannotationutils.sample.Application.main(Application.java:45)
    2015-12-24 16:14:53.496 INFO 9852 --- [ Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5390ecf8: startup date [Thu Dec 24 16:14:50 CET 2015]; root of context hierarchy
    2015-12-24 16:14:53.498 INFO 9852 --- [ Thread-1] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
    2015-12-24 16:14:53.503 INFO 9852 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown

Affects: 4.2.4

Reference URL: http://stackoverflow.com/questions/34451782/whats-wrong-within-the-usage-of-beanfactoryannotationutils

Attachments:

Issue Links:

Referenced from: commits 1d8a3e1

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions