Injection of resource dependencies failed解決辦法總結


今天調試項目代碼,出現的引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卻還沒有加載!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM