Injection of resource dependencies failed解决办法总结
今天调试项目代码,出现的引resource的报错,查原因查了好长时间才找到,现在这里总结一下,以免以后忘掉以及给大家参考。
报错大致内容入下:
1
ERROR => org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:314) - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@977f14d] to prepare test instance [com.yxcf.agriculturalLoan.platform.junit.TestDepartment@2182fb16]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘com.yxcf.agriculturalLoan.platform.junit.TestDepartment’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.yxcf.agriculturalLoan.platform.service.IDepartmentService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)}
找不到依赖的dao,什么原因,spring3 自动注解的,为什么找不到?
自己的出现这个问题的 原因是
3、第三种情况是自己在service的实现类中忘记写注解 @Service(“departmentService”)
找了很多资料,常见的有下面这个:
1、beans 的xml里面没有配置
2、第二种情况(调用死循环)
很遗憾,我的不是这个问题,我的问题是dao的调用出现死循环,即XyyyyDao实现里面,调用了他接口的本身方法:
@Repository
public class ADaoImpl extends BaseDaoImpl implements ADao {
@Resource
private ADao aDao;
@Override
public int addInbox(TInbox inbox) {
....
......
aDao.delete(id);
}
@Override
public int delete(Long id) {
…..
}
}
导致,加载ADaoImpl需要先加载完ADao,而ADao却还没有加载!