今天调试项目代码,出现的引resource的报错,查原因查了好长时间才找到,现在这里总结一下,以免以后忘掉以及给大家参考。
报错大致内容入下:
1
|
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customBlackListService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.wondershare.router.dao.CustomBlackListDao] 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)}
|
找不到依赖的dao,什么原因,spring3 自动注解的,为什么找不到?
找了很多资料,常见的有下面这个:
1、beans 的xml里面没有配置
<context:component-scan base-package="package-name"/>
2、第二种情况(调用死循环)
很遗憾,我的不是这个问题,我的问题是dao的调用出现死循环,即XyyyyDao实现里面,调用了他接口的本身方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
@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却还没有加载!