解决SpringBoot项目中的报错:Could not autowire,no beans of “XXX“ type found

问题:找不到mapper注入的bean,如图

解决SpringBoot项目中的报错:Could not autowire,no beans of “XXX“ type found

 

分析:注入mapper有两种方式:

 第一种:在启动类中添加  @MapperScan

解决SpringBoot项目中的报错:Could not autowire,no beans of “XXX“ type found

       然后在mapper的类中添加  @Repository 注解

解决SpringBoot项目中的报错:Could not autowire,no beans of “XXX“ type found

第二种方法:直接在各个mapper类中添加@Mapper注解,但是一定要注意导入正确的包,否则解决不了这个异常;

解决SpringBoot项目中的报错:Could not autowire,no beans of “XXX“ type found

解决SpringBoot项目中的报错:Could not autowire,no beans of “XXX“ type found

 很多新手在使用@Mapper的时候还是报异常,多数是因为导入了错误的包导致的(可能设置了idea自动导包的功能从而没有在意)。

问题解决~~

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/589ab0968e.html