栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

用MybatisPlus代码生成器之后,运行springboot项目报错:UnsatisfiedDependencyException: Error creating bean with name

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用MybatisPlus代码生成器之后,运行springboot项目报错:UnsatisfiedDependencyException: Error creating bean with name

用MybatisPlus代码生成器生成代码之后,运行springboot项目报错:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency expressed through field ‘userService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userServiceImpl’: Unsatisfied dependency expressed through field ‘baseMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.tang.code.mapper.UserMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:

  错误截图如下:

一、解决方法

  解决方法:在Mapper接口上查看是否存在Mapper注解,如果没有就加上。或者在SpringBoot启动类上加上MapperScan扫描注解。或者在MybatisPlus的配置类上加MapperScan扫描注解。注意后面两种方法要将Mapper接口组件注入到spring容器中,虽然不会报错,但是会爆红。如下:

或

或

二、原因分析

  用MybatisPlus代码生成插件生成的Mapper接口代码,默认不会加Mapper注解,所以spring容器找不到该组件,就会报错UnsatisfiedDependencyException。

  如果不是这里有问题的话,可以去看这篇文章:
  https://blog.csdn.net/qq_44860722/article/details/122586661

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/969489.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号