springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.
生活随笔
收集整理的這篇文章主要介紹了
springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、前言:
使用springboot自動注入的方式搭建好了工程,結果啟動的時候報錯了!!!,錯誤如下圖:
Description:Field userEntityMapper in com.xxx.xxx.service.UserService required a bean of type 'com.xxx.xxx.dao.UserEntityMapper' that could not be found.Action:Consider defining a bean of type 'com.xxx.xxx.dao.UserEntityMapper' in your configuration.二、解決方式:
1.檢查自己寫的注解是否錯了,并沒有。
2.在網上查找解決方式:如下所示:
步驟一:
在springboot的配置文件添加,mybatis的配置如下所示:
mybatis:typeAliasesPackage: com.xxx.xxx.dao.entitymapperLocations: classpath:mapper/*.xml?步驟二:
?、賹⒔涌谂c對應的實現類放在與application啟動類的同一個目錄或者他的子目錄下,這樣注解可以被掃描到,這是最省事的辦法。(沒測試)
?、诨蛘咴趩宇惿霞由?#64;MapperScan或者@ComponentScan注解,手動指定application類要掃描哪些包下的注解,如下所示:?
?、刍蛘咴诮涌谏咸砑?#64;Mapper注解。
@Mapper public interface UserMapper { }ps:之所以沒有找到對應的Bean是因為,@SpringBootApplication沒有掃描到。
參考:關于spring boot自動注入出現Consider defining a bean of type 'xxx' in your configuration問題解決方案
轉載于:https://www.cnblogs.com/louby/p/10436917.html
總結
以上是生活随笔為你收集整理的springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查询锁表并解锁
- 下一篇: 994. 腐烂的橘子