V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
tiRolin
V2EX  ›  Java

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

  •  1
     
  •   tiRolin · 8 天前 · 377 次点击

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

    首先我的项目在不适用 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 ,这个应该也没问题

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

    6 条回复
    wanglz111
        1
    wanglz111  
       8 天前   ❤️ 1
    xml 的会不会多了一个`user` dir 呢
    tiRolin
        2
    tiRolin  
    OP
       8 天前
    @wanglz111 我去,还真是这个问题,感激不尽感激不尽,真是问题都在最小处的地方啊
    tiRolin
        3
    tiRolin  
    OP
       8 天前
    @wanglz111 不过虽然解决了 User 问题,然而在另外一个 Attachment 上,却还是报这个异常,我稍后更新一下第一帖,可以麻烦你再帮忙看看吗?
    wanglz111
        4
    wanglz111  
       8 天前
    @tiRolin #3 你的 xml 里 Attachment 也多`Attachment `的 dir
    wanglz111
        5
    wanglz111  
       8 天前
    @wanglz111 #4 你只需要在 orangecommon.mapper 下放这两个 xml 即可
    tiRolin
        6
    tiRolin  
    OP
       8 天前
    @wanglz111 我已经是这么做了,然而就是在这么做的前提下仍然报这个错误,我确定我已经将两个 xml 都移动到相同的目录了,现在的情况是,我的 usermapper 是没问题的,但是 attachmentMapper 仍然存在这个问题
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2593 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 10:37 · PVG 18:37 · LAX 02:37 · JFK 05:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.