【Spring】@Autowired報錯Could not autowire. No beans of xxx

問題描述
開發工具採用的是IDEA,寫了一個DAO接口,在service中注入時,報錯:Could not autowire. No beans of xxx。

問題原因
原因在於DAO接口添加的@Mapper並不是Spring的註解,而是ibatis的註解,並沒有聲明這個DAO接口作爲Spring的Bean,因此Spring不能進行管理,導致注入報錯。

解決辦法
只需在DAO接口加上@Component 或者 @Repository(@Repository實際上也包含了@Component註解)註解聲明爲Spring的Bean即可。


--------------------- 
作者:Mr_EvanChen 
來源:CSDN 
原文:https://blog.csdn.net/Mr_EvanChen/article/details/84035445 
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章