Consider defining a bean of type ‘com.service.UserService‘ in your configuration解决方案

项目场景:

SpringBoot+MybatisPlus使用。


问题描述

Could not autowire. No beans of ‘UserMapper’ type found.


原因分析:

没有扫描到

因为这是SpringBoot整合Mybatis的代码,所以在Mapper接口类使用的是@Mapper注解。

但如果每个Mapper接口类都添加@Mapper注解比较麻烦,所以用了@MapperScan注解批量扫描Mapper接口类。


解决方案:

在xxxApplication启动类加上 @MapperScan(“com.xxx.xxx.mapper”)注解。

例如:新建一个  对象,并将读取到的数据存入 ,然后 换成 。

猜你喜欢

转载自blog.csdn.net/aaxzsuj/article/details/129328922