转:IDEA异常解决: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

原文地址:https://www.cnblogs.com/jstarseven/p/5803697.html

有时候解决问题不仅仅是解决问题。-----jstarseven

最近采用了开发工具IDEA开发SSM开发框架完成后,发布的时候出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found。。。

一开始以为是自己配置文件写的有问题找了半天也没有问题,之后才发现是自己对IDEA工具使用的不够熟悉。

原来eclipse默认会帮你整合resources目录下的mapper配置文件,而idea不能自动识别,需要额外配置。

先说该异常常见解决方案:

一般是xml映射文件有错误。但是这个提示不一定准确,以致网上有些资料说这个问题很奇怪。出现这个错误一般的解决方式在下面有说明:

一般的原因是Mapper interface和xml文件的定义对应不上,需要检查包名,namespace,函数名称等能否对应上,需要比较细致的对比。

按以下步骤一一执行:

1:检查xml文件所在的package名称是否和interface对应的package名称一一对应

2:检查xml文件的namespace是否和xml文件的package名称一一对应

3:检查函数名称能否对应上

4:去掉xml文件中的中文注释

5:随意在xml文件中加一个空格或者空行然后保存(触发了ide的自动编译功能。由于xml文件在编译的时候,不一定总能立即从源目录复制到class文件的编译目录(MyEclipse经常出这个问题),有时候你源目录中的xml文件已经修改好了,而class所在的目录里面还是旧的。因此真正确定有效的方式是将正确的xml文件复制到class输出目录。)

(博主使用IDEA工具)

但是博主在尝试以上方案之后仍然报错,在我查看了发布之后的源代码之后,发现*Mapper.xml文件并没有发布到目标文件中。

如图所示:

Mapper目录:

发布之后target目录中:

居然没有xml文件,突然意识到了异常的原因:

idea中我将mapper类型是source,而xml文件在发布时不会编译,同时也不会发布到target中,导致项目运行时找不到mapper.xml文件。

解决方案:我将*Mapper.xml文件提取到指定文件夹mapper中,设置mapper文件夹类型为resource,在application-dao.xml配置文件中添加图片中框选的代码对mapper文件进行扫描。问题解决。

总结:

(1)eclipse、myeclipse、idea针对项目的文件处理方式不一样。

eclipse和myeclipse中mapper.java和mapper.xml在同一目录下,直接配置扫描不会出现上述问题。

(2)注意xml文件的准确性。

原文地址:https://www.cnblogs.com/hirampeng/p/10099822.html

时间: 2024-07-29 15:34:02

转:IDEA异常解决: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)的相关文章

IDEA异常解决: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

有时候解决问题不仅仅是解决问题.-----jstarseven 最近因为开发需要,需要搭建一个ssm开发框架,采用了开发工具IDEA. 整合完了SSM开发框架之后,发布的时候出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found... 一开始以为是自己配置文件写的有问题找了半天也没有问题,之后才发现是自己对IDEA工具使用的不够熟悉. 先说该异常常见解决方案: 一般是xml映射文件有错误.但

解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题,即在mybatis中dao接口与mapper配置文件在做映射绑定的时候出现问题,简单说,就是接口与xml要么是找不到,要么是找到了却匹配不到. 截图为网络中搜索到的常见原因: 照着修改之后,问题依旧存在.最终花费了好大的力气才找到自己代码问题的根源.dao接口与xml的文件名不一致. 接口名与接口文件名都是DepartmentDao,

解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误

我调这个bug调了一天多,在网上搜索的检查namespace,package等,都没有错.错误提示是没有找到xml文件,我就纳闷了,为什么找不到呢?后来才发现,原来是resource中奇怪的目录为题,可以看着两个链接:https://jingyan.baidu.com/article/93f9803f51225fe0e56f5573.html,https://blog.csdn.net/benben513624/article/details/81076182. 在创建resources下目录时

spring boot 整合mybatis:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

最近在学习SpringBoot,遇到些异常情况: 1.异常信息 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.hippo.demo.dao.Chapter6DemoMapper.insert 2.解决方案 问题找了很久,发现使用@Select.@Insert.@Update.@Delete注解代替xxxMapper.xml里面的内容,不存在异常,那就是扫描xxxMapper

MyBatis笔记----报错:Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)解决方法

报错 Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.ij34.model.UserMapper.selectarticle at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:230) at or

通过maven test 报org.apache.ibatis.binding.BindingException: Invalid bound statement

背景 直接使用eclipse工具去执行,没有问题,通过testng.xml去执行,没有问题,但通过mvn clean test执行,就报错,提示org.apache.ibatis.binding.BindingException: Invalid bound statement 解决方法 首先先肯定的是:mybatis的配置是没有问题,因为eclipse可以正常执行: 在eclipse中把mapper的xml文件放到src代码目录下是可以一起打包进classes的,而maven去编译的时候不会,

MyBatis笔记----报错Exception in thread &quot;main&quot; org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.ij34.model.UserMapper.selectUser

信息: Refreshing org[email protected]41cf53f9: startup date [Wed Apr 05 16:48:12 CST 2017]; root of context hierarchy 四月 05, 2017 4:48:12 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definiti

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.baway.dao.UserMapper.register

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.baway.dao.UserMapper.register    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:189)    at org.apache.ibatis.binding.MapperMethod.<

IDEA+Maven+Mybatis 巨坑:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.rao.mapper.UserMapper.findAll

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.rao.mapper.UserMapper.findAll at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:227) at org.apache.ibatis.binding.MapperMethod.<init&