当前位置:网站首页>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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- 为什么要使用BGP?
- iNFTnews | 看见元宇宙的两面,何谓全真互联网和价值互联网?
- MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救
- 享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
- Why use BGP?
- How to choose a truly "easy-to-use, high-performance" remote control software
- matlab-day02
- 瑞萨RZ/G2L处理器详细测评
- The ggbarplot function of the R language ggpubr package visualizes the grouped histogram, sets the add parameter to mean_se to visualize the histogram of the mean values of different levels and adds
- R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the stacked bar plot, the lab.pos parameter specifies the position of the numerical label of the bar cha
猜你喜欢
games202:三,实时环境光照IBL + PRT
转转反爬攻防战
字节跳动软件测试岗,收到offer后我却拒绝了~给面试的人一些忠告....
软件测试岗位巨坑?阿里在职7年测试人告诉你千万别上当
从测试入门到测试架构师,这10年,他是这样让自己成才的
新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!
第十五章 多线程
Getting Started with SCM from Scratch (1): Summary of Background Knowledge
读博一年后对机器学习工程的思考
You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)
随机推荐
同样做软件测试,和月收入 3W 的学弟聊了一晚上,我彻底崩溃了
SVN如何删除文件名包含空格的文件
R language time series data arithmetic operation: use the log function to log the time series data, and use the diff function to calculate the successive difference of the logarithmic time series data
QT专题:事件机制event基础篇
How to encapsulate the wx.request() request of WeChat applet
R语言ggpubr包的ggbarplot函数可视化分组柱状图、设置add参数为mean_se可视化不同水平均值的柱状图并为柱状图添加误差线(se标准误差)、position参数自定义分组柱状图分离
你好,我的新名字叫“铜锁/Tongsuo”
[Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!
LayaBox---TypeScript---声明合并
Hongxing, donate another million
软件测试的基本理论知识(软件测试面试基础知识)
3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
QT专题:自定义部件
迭代器失效问题
Verilog的随机数系统任务----$random
重磅大咖来袭!阿里云生命科学与智能计算峰会精彩内容剧透
云原生应用平台的核心模块有哪些
Verilog's random number system task----$random
LayaBox---TypeScript---Decorator
软件工程国考总结——选择题