用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

posted @   爱吃雪糕的小布丁  阅读(486)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示