Results 1 to 2 of 2

Thread: @Autowired with @Qualifier dows not work as expected

  1. #1

    Default @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.
    Code:
    <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:
    Code:
    @Autowired
    @Qualifier("devTransporter")
    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:
    Code:
    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. #2

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •