springboot3整合mybatisplus报错org.apache.ibatis.binding.BindingException: Invalid bound statement

版本依赖

以下为能正常运行的版本依赖。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.jmyok</groupId>
    <artifactId>blogSystem</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>blogSystem</name>
    <description>blogSystem</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.1</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

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

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

</project>

排查过程

首先Google了一下,按照解决办法进行了排查:

1.检查配置@MapperScan(basePackages = "com.xxx.mapper")

是否为mapper所在文件夹,没有问题。

 

2.检查mybatis.mapper-locations: classpath:mapper/*.xml的配置路径是否正确

springboot默认配置为

package com.baomidou.mybatisplus.autoconfigure;
public class MybatisPlusProperties {
...
private String[] mapperLocations = new String[]{"classpath*:/mapper/**/*.xml"};   
...
}

检查下target文件夹,没有问题:

 3.注意项目的target目录下是否有mapper.xml文件,如果没有则要在pom.xml加入如下配置

<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

检查结果同上,文件夹中是有xml的,所以也不是这个问题。

4.检查是不是引入 jar 冲突

看了下pom,应该不是这个问题。

5.是否扫描路径冲突?

我只有一个@mapperscan,不存在这个问题。

6.命名空间是否正确?

 在IDEA都能够通过图标跳转,所以也没有问题。

7.版本问题

 网上搜了个遍都没能解决,说明这个问题不常见,很有可能是版本问题,所以我将mybatis和mybaits-plus的版本全部更新为最新版本。

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.3.1</version>
</dependency>

单元测试终于跑通。

@Test
    void testService(){
        long count = articleService.count();
        System.out.println("总记录数:" + count);
    }

参考

以上解决方式参考了部分以下文章,如果没有解决您的问题,可以点击下方链接继续排查:

  1. mybatis plus报Invalid bound statement (not found):解决_合格的程序员的博客-CSDN博客
  2. spring boot - Mybatis - Invalid bound statement (not found) - Stack Overflow(可继续搜索stack overflow同类问题)
  3. mybatis plus 出现 Invalid bound statement (not found) | 搬砖的码农

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值