I have a number of Spring beans, some of which are in a jar with a shared library. It seems I can not work @Qualifier
.
I have default-autowire set to "byType", this uses Spring 3.1.0.M2 and works as a standalone executable. If I remove "TestTwoBean" from the shared library, the project will execute 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 a "unique bean exception named" at runtime:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name "testConsumerBean" defined in file [-]: Invalid dependency expressed through bean property 'bean' :: No unique bean of type [com.myco.ITestBean] : expected single match bean, but found 2: [testOneBean, testTwoBean]; nested exception org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.myco.TestBean]: expected single bean match, but found 2: [testOneBean, testTwoBean] in org.springframework.beans.factory.sute. .autowireByType (AbstractAutowireCapableBeanFactory.java:1167) ...
Does @Qualifier
in this situation? Is a workaround known?
source share