c_7y143 2022-04-06 15:09 采纳率: 75%
浏览 249
已结题

springBoot+mybatis plus项目测试类无法注入bean

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.example.mybatisplus.MyBatisPlusTest': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.mybatisplus.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

我的解答思路和尝试过的方法

①包名是一致的

img


②有扫描mapper

img


③版本也没问题

img


img

我想要达到的结果
  • 写回答

1条回答 默认 最新

  • 一起随缘 2022-04-06 15:16
    关注

    首先扫描路径到com.example.mybatisplus目录即可,另外,UserMapper接口上要添加@Mapper注解

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月14日
  • 已采纳回答 4月6日
  • 创建了问题 4月6日