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.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
Due to its origin (i.e. transaction manager selection and async executor selection), BeanFactoryAnnotationUtils historically just deals with qualifier values on explicit bean definitions and with analogous qualifier annotations on @Bean factory methods. It simply does not honor qualifier annotations on bean classes at all since those do not occur in the original scenarios that motivated this utility class in the first place.
Of course, arguably BeanFactoryAnnotationUtils should be extended to cover that variant as well, bringing it in sync with QualifierAnnotationAutowireCandidateResolver's algorithm for injection point matching. I've turned this issue into a corresponding feature ticket, to be addressed for 4.3.
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.
An interface QualifiedInterface.java
and QualifiedB.java :
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)
Affects: 4.2.4
Reference URL: http://stackoverflow.com/questions/34451782/whats-wrong-within-the-usage-of-beanfactoryannotationutils
Attachments:
Issue Links:
@Async
@Transactional
Referenced from: commits 1d8a3e1
The text was updated successfully, but these errors were encountered: