SpringBoot 3 项目 mybatis-plus报错解决:org.apache.ibatis.binding.BindingException: Invalid bound statement

2023-09-17 08:33:16 浏览数 (1)

遇到一个坑花了半个多小时才解决,记录在此以防其他人遇到类似问题。

问题现象

SpringBoot 3.1.3 ,使用了 mybatis-plus 3.5.1 版本,运行报错:

代码语言:javascript复制
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxxMapper.insert

	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:229)
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)
	at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:96)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
	at org.apache.ibatis.util.MapUtil.computeIfAbsent(MapUtil.java:36)
	at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:94)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)
	at jdk.proxy2/jdk.proxy2.$Proxy62.insert(Unknown Source)
	at com.baomidou.mybatisplus.extension.service.IService.save(IService.java:63)
  //...
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

看了很多文章发现都没用,最后在 Github issue 找到原因:mybatis-plus 3.5.3 开始才支持 Spring Boot 3!

解决办法:

所以解决办法就是升级 mybatis-plus 版本到 3.5.3 以后。

2023.09.16 官方给的最新版本是:3.5.3.2

代码语言:javascript复制
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus</artifactId>
    <version>3.5.3.2</version>
</dependency

我本地升到 3.5.3 就好了:

代码语言:javascript复制
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.3</version>
        </dependency>

顺便贴下其他版本:

  1. JDK 17
  2. SpringBoot 3.1.3
  3. Mybatis 3.0.2
代码语言:javascript复制
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter-test</artifactId>
            <version>3.0.2</version>
            <scope>test</scope>
        </dependency>

相关链接

https://github.com/baomidou/mybatis-plus/issues/4997

0 人点赞