Spring Boot 項目,啟動報錯:
Field xxMapper in xx.service.impl.xxServiceImpl required a bean of type 'xx.mapper.xxMapper'

原因: *** 項目未掃描到mapper包
解決方法: 在項目啟動類上加注解 @MapperScan("Mapper文件所在的包") 重啟項目即可
@MapperScan和@ComponentScan的區別:
天在擼SpringBoot的時候,突然對注解產生了混淆,@MapperScan和@ComponentScan都是掃描包,二者之間有什么區別呢?
首先,@ComponentScan是組件掃描注解,用來掃描@Controller @Service @Repository這類,主要就是定義掃描的路徑從中找出標志了需要裝配的類到Spring容器中
其次,@MapperScan 是掃描mapper類的注解,就不用在每個mapper類上加@MapperScan了
這兩個注解是可以同時使用的。
https://blog.csdn.net/m0_37597572/article/details/82625631
@ComponentScan說明
https://blog.csdn.net/Lamb_IT/article/details/80918704
@MapperScan說明
https://blog.csdn.net/nba_linshuhao/article/details/82783454
