springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.
一、前言:
使用springboot自動(dòng)注入的方式搭建好了工程,結(jié)果啟動(dòng)的時(shí)候報(bào)錯(cuò)了!!!,錯(cuò)誤如下圖:
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.檢查自己寫的注解是否錯(cuò)了,并沒有。
2.在網(wǎng)上查找解決方式:如下所示:
步驟一:
在springboot的配置文件添加,mybatis的配置如下所示:
mybatis:typeAliasesPackage: com.xxx.xxx.dao.entitymapperLocations: classpath:mapper/*.xml?步驟二:
①將接口與對(duì)應(yīng)的實(shí)現(xiàn)類放在與application啟動(dòng)類的同一個(gè)目錄或者他的子目錄下,這樣注解可以被掃描到,這是最省事的辦法。(沒測(cè)試)
②或者在啟動(dòng)類上加上@MapperScan或者@ComponentScan注解,手動(dòng)指定application類要掃描哪些包下的注解,如下所示:?
③或者在接口上添加@Mapper注解。
@Mapper public interface UserMapper { }ps:之所以沒有找到對(duì)應(yīng)的Bean是因?yàn)?#xff0c;@SpringBootApplication沒有掃描到。
參考:關(guān)于spring boot自動(dòng)注入出現(xiàn)Consider defining a bean of type 'xxx' in your configuration問題解決方案
轉(zhuǎn)載于:https://www.cnblogs.com/louby/p/10436917.html
總結(jié)
以上是生活随笔為你收集整理的springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查询锁表并解锁
- 下一篇: 994. 腐烂的橘子