Injection of resource dependencies failed解决办法总结

Posted on 2013-12-20 21:24  炫谷  阅读(158782)  评论(3编辑  收藏  举报

今天调试项目代码,出现的引resource的报错,查原因查了好长时间才找到,现在这里总结一下,以免以后忘掉以及给大家参考。

报错大致内容入下:

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实现里面,调用了他接口的本身方法:

@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却还没有加载!

Copyright © 2024 炫谷
Powered by .NET 8.0 on Kubernetes