admin管理员组

文章数量:1531705

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依赖,搞了半天才解决。

本文标签: DependencyexpressedTMUnsatisfiedField