5
[3.0.5彈簧] [JBoss的5.1]爪哇/彈簧問題的@Service和@Autowired註解
我有標記爲@Service
,它實現泰德相同的接口的幾個類。
例如,
@Service(value="test1")
public TestImpl1 implements Test {}
@Service(value="test2")
public TestImpl2 implements Test {}
接下來,我有以下結構
public SomeClass {
@Autowired
@Qualifier("test1")
Test test1;
@Autowired
@Qualifier("test2")
Test test2;
我得到一個異常(在部署)
10:36:58,277 ERROR [[/test-web]] Servlet /test-web threw load()
exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
unique bean of type [pl.tests] is defined: expected single matching
bean but found 2: [test1, test2]
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doReso lveDependency(DefaultListableBeanFactory.java:
796)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolv eDependency(DefaultListableBeanFactory.java:
703)
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostPro cessor
$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:
474)
任何人知道如何解決這個問題?
T.
什麼是'pl.tests`加入
@Qualifier("test1")
? – skaffman 2011-02-11 11:55:02對不起,pl.tests.SomeClass – user6778654 2011-02-11 12:46:37