I have a number of Spring beans, some of which are in a shared library jar. I can't seem to get @Qualifier
to work.
I have default-autowire set to "byType", this is using Spring 3.1.0.M2 and running as a standalone executable. If I remove "TestTwoBean" from the shared library the project executes as expected.
myproj-shared-lib.jar:
@Service
public class TestOneBean implements ITestBean {
}
@Service
public class TestTwoBean implements ITestBean {
}
myproj.jar:
@Service
public class TestConsumerBean {
@Autowired @Qualifier("testOneBean")
private ITestBean bean;
}
I get the "no unique bean with name" exception at runtime:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testConsumerBean' defined in file [-]: Unsatisfied dependency expressed through bean property 'bean': : No unique bean of type [com.myco.ITestBean] is defined: expected single matching bean but found 2: [testOneBean, testTwoBean]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.myco.TestBean] is defined: expected single matching bean but found 2: [testOneBean, testTwoBean] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1167) ...
Does @Qualifier
not work in this situation? Is there a known workaround?