当前位置:网站首页>org.apache.ibatis.binding.BindingException Invalidbound statement (not found)的解决方案和造成原因分析(超详细)
org.apache.ibatis.binding.BindingException Invalidbound statement (not found)的解决方案和造成原因分析(超详细)
2022-08-02 10:15:00 【免费的东西】
一、问题描述
今天使用SpringBoot整合mybaits时报了绑定异常的错误:
AbstractHandlerExceptionResolver.java:194
|org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver
|Resolved exception caused by handler execution: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.guli.edu.mapper.CourseMapper.getCoursePublishVoById
二、问题分析
出现这种错误,首先检查一下自己的xml文件中的id、resultMap等属性有没有写错,我检查了一下,应该都是正确的。
再看看target文件夹,xml文件夹为空

那么这已经可以基本确定问题了。
三、错误原因
这个错误是maven默认加载机制造成的问题。maven加载时候,把java文件夹里面.java类型文件进行编译,如果是其他类型文件,则不会被加载。dao层编译后只有class文件,没有mapper.xml,因为maven工程在默认情况下src/main/java目录下的所 有资源文件是不发布到target目录下的。
四、解决方案
1、把mybatis的xml文件直接复制到target目录中
这个方法可以解决问题,但是每次手动复制也挺笨的,不推荐使用
2、把xml文件放在resources目录下
resources目录下的文件是会编译的。但是这样的操作会破坏项目结构,特别是自动生成出来的代码,不建议使用这种方法。
3、通过配置解决(推荐使用)
项目中的两个地方都要配置,不要只配置一个地方
(1)pom.xml中
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
(2)application.properties中
#配置mapper xml的路径
mybatis-plus.mapper-locations=classpath:com/shang/eduservice/mapper/xml/*.xml
上述三种方法均能解决问题。
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- 第十七章 Excel操作
- LayaBox---TypeScript---命名空间和模块
- 8年软件测试工程师的感悟:与薪资相匹配的永远是实力
- npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
- R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the horizontal column chart (bar chart), use the orientation parameter to set the column chart to be tra
- LayaBox---TypeScript---Mixins
- Jay Chou's new song is released, crawl the "Mojito" MV barrage, and see what the fans have to say!
- Rust 从入门到精通03-helloworld
- 周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...
- Do you agree with this view?Most businesses are digitizing just to ease anxiety
猜你喜欢

小几届的学弟问我,软件测试岗是选11k的华为还是20k的小公司,我直呼受不了,太凡尔赛了~

WPF 截图控件之文字(七)「仿微信」

如何搭建威纶通触摸屏与S7-200smart之间无线PPI通信?

MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救

周杰伦新歌发布,爬取《Mojito》MV弹幕,看看粉丝们都说的些啥!

周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...

How to choose a truly "easy-to-use, high-performance" remote control software

牛客刷题——剑指offer(第三期)

Why use BGP?

iNFTnews | 看见元宇宙的两面,何谓全真互联网和价值互联网?
随机推荐
sqlmap安装教程用w+r打开(sqlyog安装步骤)
LayaBox---TypeScript---JSX
享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
The ggline function of the R language ggpubr package visualizes grouped line graphs, the add parameter is mean_se and dotplot to visualize line graphs of different level averages, and adds error bars
LayaBox---TypeScript---三斜线指令
使用较广泛的安全测试工具有哪些?
Linux系统卸载,安装,升级,迁移clickHouse数据库
Getting Started with SCM from Scratch (1): Summary of Background Knowledge
wireshark的安装教程(暖气片安装方法图解)
【术语科普】关于集成工作台那些难懂的词儿,看这篇秒懂!
LayaBox---TypeScript---Symbols
MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救
适配器模式适配出栈和队列及优先级队列
Jay Chou's new song is released, crawl the "Mojito" MV barrage, and see what the fans have to say!
qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
The 38-year-old daughter is not in love and has no stable job, the old mother is crying
Hongxing, donate another million
currentstyle 织梦_dede currentstyle属性完美解决方案
8年软件测试工程师的感悟:与薪资相匹配的永远是实力
R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色