Announcement Announcement Module
No announcement yet.
@Autowired with @Qualifier dows not work as expected Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Autowired with @Qualifier dows not work as expected

    Hi all,
    I have two classes implementing the same interface. I have described them in a xontext xml as 2 beans.
    <bean id="transporter" class="com.medicum.tns.transport.impl.LiveSOAPMsgTransporterImpl" />
    <bean id="devTransporter" class="com.medicum.tns.transport.impl.DevSOAPMsgTransporterImpl"/>
    I am using annotations to inject second bean:
    private SOAPMsgTransporter transporter;
    I want to inject bean by name, because there are 2 beans implementing the same interface. So I added @Qualifier annotation. It does not work and gives an exception:
    Error creating bean with name 'documentService': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.medicum.tns.transport.SOAPMsgTransporter com.medicum.tns.service.ehealth.DocumentService.transporter; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.medicum.tns.transport.SOAPMsgTransporter] is defined: expected single matching bean but found 2: [transporter, devTransporter]
    What i did wrong?
    Thank you.

  • #2
    Sorry for this post. Actually the problem was with the other bean. I have added second bean in the context, but forgot to add @Qualifier to old services. My fault.