0
我有以下测试类:弹簧自动装配数据不工作
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:ApplicationContext.xml")
public class CompoundServiceImplTest {
@Autowired
@Qualifier("testCompoundService")
private TestCompoundService testCompoundService;
//...
}
和ApplicationContext中包含:
<bean id="testCompoundService" autowire="byType"
class="myPackage.TestCompoundService">
</bean>
如果还试图自动装配绰号或离开@Qualifier远(我补充说,因为它没有不工作,但也没有帮助)。
我得到以下异常:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No matching bean of type [myPackage.TestCompoundService] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true),
@org.springframework.beans.factory.annotation.Qualifier(value=testCompoundService)}
这个bean显然还配置春季声称它是不是?
我该如何解决这个问题?
编辑:
当我改变@Autowired到@Resource我获得以下错误:
Injection of resource dependencies failed;
nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'testCompoundService' must be of type [myPackage.TestCompoundService],
but was actually of type [$Proxy68]
相关/重复:http://stackoverflow.com/questions/14509142,http://stackoverflow.com/questions/11535527,http://stackoverflow.com/questions/8391944和其他许多人 – 2013-02-11 18:30:35