nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

编程入门 行业动态 更新时间:2024-10-28 03:25:29

nested exception is org.<a href=https://www.elefans.com/category/jswz/34/1769910.html style=apache.ibatis.binding.BindingException: Invalid bound statement (not found):"/>

nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

报错问题:
mapper绑定异常 nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxx.xxxx.mapper.UserMapper.getAllUser] with root cause


错误日志:

2022-03-23 19:26:05.834 ERROR 26256 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;  nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxx.xxxx.mapper.UserMapper.getAllUser] with root causeorg.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxx.xxxx.mapper.UserMapper.getAllUser

背景:

mapper接口和**mapper.xml映射文件**在同一个包下。


排查过程:

​ 在看到 **Invalid bound statement (not found)**后,提示未找到mapper映射文件,然后打开编译后的target包或生成的jar包后,找到mapper映射文件存放位置,发现编译后的jar包内并没有此映射文件,进而将问题指向到Maven编译的过程中没有将普通配置文件编译进jar包内。


报错原因:

由于我把mapper映射文件放在mapper接口的同一包里,并没有放在resources目录下,导致通过Maven编译后没有把除Java以外的映射文件、配置文件编译到target和jar包内,在运行时,调用mapper映射文件时,发现在同一个目录下没有找到mapper映射文件而报错。

​ 我们知道Maven是根据pom.xml执行任务,其中build标签描述了如何来编译及打包项目,而具体的编译和打包工作是通过build中配置的 plugin 来完成。而对于resources目录下资源,往往不是代码(.propertiesXML配置文件),无需编译,所以在构建过程中往往会将资源文件从源路径直接复制到指定的目标路径。

src/main/javasrc/test/java这两个目录中的所有*.java文件会分别在comiletest-comiple阶段被编译,编译结果分别放到了target/classestarge/test-classes目录中,但是这两个目录中的其他文件都会被忽略掉。


解决办法:

需要在你的项目的pom文件中添加一下配置

<build><resources><!-- 解决mapper绑定异常 --><resource><directory>src/main/java</directory><includes><include>**/*.yml</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><!-- 解决未找到数据源等配置异常 --><resource><directory>src/main/resources</directory><includes><include>**/*.yml</include></includes></resource></resources>
</build>

更多推荐

nested exception is org.apache.ibatis.binding.BindingException: Invalid bound st

本文发布于:2024-03-07 15:54:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1718251.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:apache   ibatis   org   nested   exception

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!