Spring mvc 錯誤:org.springframework.beans.factory.BeanCreationException


今天在做項目的是時候啟動一直報錯:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'codeManager': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.igaming.business.mapper.ReddemCodeMapper com.igaming.gm.manager.CodeManager.reddemCodeMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.igaming.business.mapper.ReddemCodeMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 
最后發現原因如下:
使用spring依賴注入,有嚴格的要求,必須要先有對象了,才能依賴注入。
因為在這個項目中,項目框架結構是直接拷貝的以前的項目框架,然后我在做的時候新加了包:
 
而且以前的項目,在spring配置文件寫的是
com.igaming.gm.manager
 

還有就是項目中是不允許出現如下情況出現的:
 
 
 
今天啟動項目發現又報這個錯誤,最后發現是@Service的包導錯了,導成阿里巴巴的了。所以啟動一直報錯。
正確的應該是:
import org.springframework.stereotype.Service;

 

 

 


免責聲明!

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



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