maven搭建web项目中org.apache.ibatis.binding.BindingException:Invalid bound statement ( not found)
2018-01-07 00:54
726 查看
最近使用Maven配合SSM(Spring+SpringMVC+Mybatis)搭建一个Web项目,在测试三个框架是否整合成功的时候,每次发出请求调用MyBatis时都会出现下面这个错误
从异常信息的提示来看是一个无效的语句绑定错误,一般出现该错误是由于MyBatis的Mapper映射的xml文件丢失或者没配置好,于是检测自己的映射文件
发现自己的配置文件存在,而且xml的书写也没问题,于是推测问题可能出在当使用Maven运行项目时项目中生成的目标的文件都会在target文件夹下,而且web项目的运行正是依靠于target文件下的这些class文件,Mapper映射接口的class文件要想正确运行则在target目录下必须也存在对应的Mapper映射的XML文件。检查自己的target目录下对应文件夹果真是由于缺少Mapper接口的XML配置文件造成的问题,下面进行解决
解决办法:
方法一:只需要将XML文件复制到target文件下相应目录即可解决上面出现的BindingException。
方法二:方法一是一种治标不治本的解决方案,之所以这样说是由于当我们修改了Mapper的XML文件的内容重新运行项目时又需要手工的将修改的文件复制再次复制过去,相当的麻烦,当项目中XML较多时这个方法完全不合理。经过查阅相关资料,我们可以把拷贝XML文件的这件事交给Maven来替我们做,只需要在Mavaen项目中Mapper对应的子工程的pom.xml文件中添加以下配置即可
[html] view
plain copy
<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
添加完成后,测试成功。
从异常信息的提示来看是一个无效的语句绑定错误,一般出现该错误是由于MyBatis的Mapper映射的xml文件丢失或者没配置好,于是检测自己的映射文件
发现自己的配置文件存在,而且xml的书写也没问题,于是推测问题可能出在当使用Maven运行项目时项目中生成的目标的文件都会在target文件夹下,而且web项目的运行正是依靠于target文件下的这些class文件,Mapper映射接口的class文件要想正确运行则在target目录下必须也存在对应的Mapper映射的XML文件。检查自己的target目录下对应文件夹果真是由于缺少Mapper接口的XML配置文件造成的问题,下面进行解决
解决办法:
方法一:只需要将XML文件复制到target文件下相应目录即可解决上面出现的BindingException。
方法二:方法一是一种治标不治本的解决方案,之所以这样说是由于当我们修改了Mapper的XML文件的内容重新运行项目时又需要手工的将修改的文件复制再次复制过去,相当的麻烦,当项目中XML较多时这个方法完全不合理。经过查阅相关资料,我们可以把拷贝XML文件的这件事交给Maven来替我们做,只需要在Mavaen项目中Mapper对应的子工程的pom.xml文件中添加以下配置即可
[html] view
plain copy
<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
添加完成后,测试成功。
相关文章推荐
- 【问题解决】Maven搭建Web项目中org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问
- Intelij IDEA中web项目抛org.apache.ibatis.binding.BindingException: Invalid bound statement(not found):异常
- maven打包项目后org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- 运行Maven项目:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- IDEA的maven项目出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误解决方法
- maven项目中,遇到org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- Maven 遇到mybatis 发生org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- Maven 遇到mybatis 发生org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- springboot项目打包后运行报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- mybatis maven打包出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误
- idea报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.money.*
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.png.mapper.User
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 解决过程
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- maven请求报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- mybatis使用时org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):的错误
- nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- mybatis绑定错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yj.dao.TrailerA