解决Invalid bound statement (not found)(Mybatis的Mapper绑定问题)
一、问题描述
使用mybatis的项目在本地可以正常运行,但当使用maven或Jenkins打包部署到服务器上时出现了绑定错误,异常信息为:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yo.news.user.mapper.UserMapper.getUserByTelPwd
二、问题分析和解决方法
首先,给定的异常提示信息并不精准,有多个错误原因都会抛出该异常。mybatis出现这个问题,通常是由Mapper interface和对应的xml文件的定义对应不上引起的,这时就需要仔细检查对比包名、xml中的namespace、接口中的方法名称等是否对应。我之前就因为称忘记在xml标签的id属性中添加方法名或写错方法名而出现这个错误。
出现这个错误时,按以下步骤检查一般就会解决问题:
1:检查xml文件所在package名称是否和Mapper interface所在的包名一一对应;
2:检查xml的namespace是否和xml文件的package名称一一对应;
3:检查方法名称是否对应;
4:去除xml文件中的中文注释;
5:随意在xml文件中加一个空格或者空行然后保存。
--------------------------------
原来Maven 为我们提供了一致的项目目录配置(源文件夹、资源文件夹等),在自动构建项目时, Maven 会按照这个配置来执行操作(编译源文件、拷贝资源文件),Maven 默认的源文件夹及资源文件夹的配置代码如下:
<build>
<sourceDirectory>src/main/java</sourceDirectory >
<testSourceDirectory>src/test/java</testSourceDirectory >
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>
解决方案有2种:
1、可以把xml文件放到resource目录下,这样项目构建的时候会加载到target。
2、在pom.xml文件build添加resource资源列表。
<!--这个元素描述了项目相关的所有资源路径列表,例如和项目相关的属性文件,这些资源被包含在最终的打包文件里。-->
<resources>
<resource>
<!-- 描述存放资源的目录,该路径相对POM路径-->
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
总结
如果出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误,一般的原因是Mapper interface和xml文件的定义对应不上,需要检查包名,namespace,函数名称等能否对应上,需要比较细致的对比,按以下步骤一一执行:
1、检查xml文件所在的package名称是否和interface对应的package名称一一对应
2、检查xml文件的namespace是否和xml文件的package名称一一对应
3、检查函数名称能否对应上
4、去掉xml文件中的中文注释
5、随意在xml文件中加一个空格或者空行然后保存
除此之外,我遇到的还有一些特殊情况,耽误了我不少时间,网上有其他原因也导致bound找不到:
1、Intellij Idea 的包名和目录名生成机制,新建一个包a.b.c.d,目录结构不是a->b->c->d,而是生成"a.b.c.d"的目录,进而导致mybatis映射错误,此错误很难排查。
2、xml文件定义如下:
<select id="countMembers" parameterMap="java.util.Map" resultType="java.lang.Integer">
parameterMap用错,应该为parameterType,此错误会导致mybatis所有的mapper都报绑定错误,很坑。
解决Invalid bound statement (not found)(Mybatis的Mapper绑定问题)的更多相关文章
- 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.User ...
- [转载]Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByExample: 错误
因碰到同样的问题,使用该方法对我有效,为方便以后查找,所以做了转载,原文请查看:https://www.cnblogs.com/fifiyong/p/5795365.html 在Maven工程下,想通 ...
- Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByExample: 错误
在Maven工程下,想通过controller接收url中的参数Id查询数据库的数据,并且以json形式显示在页面. 在浏览器输入url后出现的问题: 八月 22, 2016 1:45:22 下午 o ...
- Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByExample问题解决
最近在做一个关于ssm框架整合的项目,但是今天正合完后出现了问题: Invalid bound statement (not found): com.taotao.mapper.TbItemMappe ...
- 项目启动报错org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.wuhongyu.mapper.OrdersMapper.selectByExample
在用maven配置mybatis环境时出现此BindingExceptiony异常,发现在classes文件下没有mapper配置文件,应该是maven项目没有扫描到mapper包下的xml文件, 在 ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.shen.mapper.UserMapper.findById
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.shen.mapper.Use ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.bw.mapper.BillMapper.getBillList at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:225
这个错误是没有找到映射文件 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.b ...
- Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByPrimaryKey
Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByPrimaryKey Invalid bound ...
- 解决Invalid bound statement (not found)的异常
今天在搭建框架的时候,报了一个Invalid bound statement (not found)的异常 经过分析,得出原因: 我的mybatis相关的dao和mapper.xml是通过逆向工程生成 ...
随机推荐
- rbenv的使用
创建: 2017/09/05 更新: 2018/02/03 增加更新rbenv和获取list没有的版本 更新: 2018/02/25 把path里面[个人主机名]全部替换为[主机名] 更新: 2018 ...
- 51nod 1428【贪心】
思路: 就是先排序,然后对每个取最小的结束时间. #include <bits/stdc++.h> using namespace std; typedef long long LL; c ...
- Codeforces703B Mishka and trip
题意: 就是有n个点,本来相邻点之间就有一条边,1和n之间也有一条,然后给你几个特殊点,说这些特殊点和其他所有点都连起来了,然后算一个所有边的权值和,每条边的权值等于两个点的c相乘. 思路: 水题啊- ...
- hdoj1106
果然...这种一条字符串的处理,还是不熟练,居然wa了四次--. 预处理预处理!!!!: 然后中间对条件的确定,标记的改变+预处理,不够严谨啊!!! #include<cstdio> #i ...
- 每天一水poj1502【最短路】
#include<iostream> #include<cstdio> #include<string.h> #include<algorithm> u ...
- bzoj 5496: [2019省队联测]字符串问题【SAM+拓扑】
有一个想法就是暴力建图,把每个A向有和他相连的B前缀的A,然后拓扑一下,这样的图是n^2的: 考虑优化建图,因为大部分数据结构都是处理后缀的,所以把串反过来,题目中要求的前缀B就变成了后缀B 建立SA ...
- iOS UITextView 设置圆角边框线
textView.layer.borderColor = UIColor.lightGray.cgColor textView.layer.cornerRadius = 4 textView.laye ...
- HDU2586(tarjanLCA板子)
; int T, n, m; int f[maxn], vis[maxn], dis[maxn], ans[maxn]; vector<P> vc[maxn]; vector<int ...
- Kruskal HDOJ 1863 畅通工程
题目传送门 /* 此题为:HDOJ 1233 + HDOJ 1232 */ #include <cstdio> #include <algorithm> #include &l ...
- Contextual Action bar(1) CAB in Android
Contextual Action bar (CAB) in Android BY PARESH MAYANI - OCTOBER, 23RD 2013 Before getting into the ...