解决:Field xxMapper in xx.service.impl.xxServiceImpl required a bean of type 'xx.mapper.xxMapper'

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

 

posted @ 2019-11-01 10:45  蓝鲸也是鲸  阅读(18560)  评论(0编辑  收藏  举报