SpringBoot異常:Unsatisfied dependency expressed through field 'mapper'解決辦法

今日改造SpringBoot項目時,發現部分子項目下的頁面報錯,異常信息顯示爲:創建Bean錯誤,底層的原因是無法找到Mapper文件的依賴關係,Spring無法自動裝配,建議將自動裝配設置爲true

經過一番的瞭解與學習,通過添加@MapperScan即可解決,記錄以備後用!

完整的異常信息爲:

{success=false, errorMessage=Error creating bean with name 'XXXController': Unsatisfied dependency expressed through field 'XXXService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'XXXService': Unsatisfied dependency expressed through field 'mapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.XXX.modules.XXX.mapper.XXXMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}, message=org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'XXXController': Unsatisfied dependency expressed through field 'XXXService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'XXXService': Unsatisfied dependency expressed through field 'mapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.XXX.modules.XXX.mapper.XXXMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}}

解決辦法:

在SpringBoot的Application中添加@MapperScan註解,value=“"com.**.mapper"”

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