SpringBoot 调用 XML 接口报 Invalid bound statement (not found)问题怎么解决?

44 天前
tiRolin  tiRolin

做毕设的时候遇到的这个问题

首先我的项目在不适用 XML 的前提下的 CURD 都是成功的,但是只要一使用 XML ,那么就报上面的异常,项目结构如下

我的 Spring 版本是 3.4.2 、mybatis-plus 版本是 3.5.9

Mapper 接口中加入了 @Mapper 注解,启动类里也加入了 MapperScan 扫描

resource 中的 xml 我是在 application 中指定了扫描路径的

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

xml 文件中的接口名和命名空间都没有问题,下面是具体的 XML 代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.rolin.orange.orangecommon.mapper.UserMapper">

    <select id="getAll" resultType="com.rolin.orange.orangecommon.model.user.entity.User">
        select * from user
    </select>
</mapper>

Mapper 代码也没有问题,可以成功编译,可以成功启动

在编译后的结果里,可以找到对应的 xml 文件

感觉不管是哪里都没有问题,但是只要调用接口,就会报下面的异常

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.rolin.orange.orangecommon.mapper.UserMapper.getAll
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:229) ~[mybatis-3.5.16.jar:3.5.16]
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:50) ~[mybatis-plus-core-3.5.9.jar:3.5.9]
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda$cachedInvoker$0(MybatisMapperProxy.java:99) ~[mybatis-plus-core-3.5.9.jar:3.5.9]
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
	at org.apache.ibatis.util.MapUtil.computeIfAbsent(MapUtil.java:36) ~[mybatis-3.5.16.jar:3.5.16]
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedInvoker(MybatisMapperProxy.java:97) ~[mybatis-plus-core-3.5.9.jar:3.5.9]
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.5.9.jar:3.5.9]
	at jdk.proxy2/jdk.proxy2.$Proxy98.getAll(Unknown Source) ~[na:na]
	at com.rolin.orange.orangecommon.service.UserService.getAll(UserService.java:84) ~[classes/:na]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]

我最后怀疑会是依赖的问题,但是查了下,springboot3.4.2 对应的 mybatisplus 版本就是 3.5.9 ,这个应该也没问题

到了这一步我实在是搞不懂到底是因为什么原因导致的这个问题了,有没有大佬帮忙解决一下?小弟我是感激不尽啊

683 次点击
所在节点    Java
6 条回复
wanglz111
44 天前
xml 的会不会多了一个`user` dir 呢
tiRolin
44 天前
@wanglz111 我去,还真是这个问题,感激不尽感激不尽,真是问题都在最小处的地方啊
tiRolin
44 天前
@wanglz111 不过虽然解决了 User 问题,然而在另外一个 Attachment 上,却还是报这个异常,我稍后更新一下第一帖,可以麻烦你再帮忙看看吗?
wanglz111
44 天前
@tiRolin #3 你的 xml 里 Attachment 也多`Attachment `的 dir
wanglz111
44 天前
@wanglz111 #4 你只需要在 orangecommon.mapper 下放这两个 xml 即可
tiRolin
44 天前
@wanglz111 我已经是这么做了,然而就是在这么做的前提下仍然报这个错误,我确定我已经将两个 xml 都移动到相同的目录了,现在的情况是,我的 usermapper 是没问题的,但是 attachmentMapper 仍然存在这个问题

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1111313

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX