解决: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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM