运行Maven项目:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
2017-02-02 10:34
519 查看
问题:
用Maven + Spring + SpringMVC + mybatis搭建项目时,测试项目是否能够运行,报了以下错误:原因分析:
从报错原因可以知道,错误原因是 mybatis框架的错误, 无效的绑定语句,出现这个原因一般是mapper配置文件出错或者丢失,然而检查mapper配置文件,发现没有丢失,也没有出错。既然mybatis中配置不存在问题,那么问题极有可能在Maven中!因此分析一下Maven,Maven项目运行的目标文件例如class文件,都会在target文件夹中
target文件夹内:
Maven管理下的web项目正是依靠taget文件夹下的classes文件,当我们执行xxxMapper.class文件时,由mybatis的规则可以知道,mapper映射文件xxxMapper.xml必须和xxxMapper.java文件在同一个目录,然而当前再classes文件中,只有class文件,而没有xml文件,因此运行class文件的方法时,根本找不到对应的映射语句,这就造成了语句绑定失效
解决方法:
复制xml映射文件到target的class文件同目录下(这样做非常麻烦,当mapper文件很多的情况下)把xml配置的事由Maven来管理:
在该项目的pom.xml文件下,加上:
<!-- 如果不添加此节点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扫描java/main/src文件时,要把.properties和.xml文件也扫描上!
最后问题解决
相关文章推荐
- maven打包项目后org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- maven搭建web项目中org.apache.ibatis.binding.BindingException:Invalid bound statement ( not found)
- springboot项目打包后运行报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搭建Web项目中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):
- mybatis maven打包出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误
- Intelij IDEA中web项目抛org.apache.ibatis.binding.BindingException: Invalid bound statement(not found):异常
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- 疑难杂症(4) -- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- Srping mvc mabatis 报错 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)新的异常解决方案
- IDEA异常解决: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- mybatis绑定错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- Exception:HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)