神TM的Unsatisfied dependency expressed through field ‘baseMapper‘;Dependency annotations:Autowired

Unsatisfied dependency expressed through field 'baseMapper'; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.demo.mapper.TestMapper' 
available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

前阵子用快速构建个springboot的demo测试一些东西,然后运行后一直报错。

1.检查springboot的配置文件

配置了放在resources的xml路径。没发现问题。

mybatis-plus:
  mapper-locations: classpath:/mapper/*.xml

在这里插入图片描述

2.检查了启动类

@MapperScan(“com.example.demo.mapper”):注解扫描了包下mapper接口。也没发现问题。

@MapperScan("com.example.demo.mapper")// 扫描Mapper接口所在的包
@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

在这里插入图片描述

3.检查xml的里的路径映射。

也没发现有问题。

在这里插入图片描述

4.检查springboot的版本和mybatis-plus的版本

SpringBoot3和旧的2.X版本Mybatis-plus会有问题,参考这篇文章
SpringBoot3整合MyBatis报错:Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required

在这里插入图片描述

5.个人问题解决

我的依赖版本配置如下,2.3.10的SpringBoot想着也没问题啊。那么mybatis的3.X版本按理来说也问题才对。一眼看过去一开始没发现问题。

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.10.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>3.5.1</version>
        </dependency>

看第二遍mybatis的版本,发现不对劲,之前用的都是mybatis的start才对,这样就有自动配置。于是修改为starter的mybatis依赖:

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.2</version>
        </dependency>

重启后,不报错了,裂开QAQ。不知道快速创建项目的时候怎么搞了个错误的mybatis依赖,搞了半天才解决。

  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值