记一次mybatis bindingexception 问题排查
看到的错误信息如出一辙都是这样的:Method threw 'org.apache.ibatis.binding.BindingException' exception.Invalid bound statement (not found): **.dao.**Dao.select
1.考虑返回值类型是否不匹配,一顿修改,@Results 也使用到。 最终无果。
2.开始各种百度,先申明本人使用的方式注解方式, 并非最常用的xml方式。 百度内容大都雷同,检查包名,类名,方法名 是否映射。无果。
3.由于 mybatis 报的错误,不是很明确。 无奈只能debug 源码。
4. 查看更为详细的异常日志
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.sankuai.meituan.banma.thrift.activity.admin.dao.CouponPossessDao.selectUnusedPageNum
- at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:214) ~[mybatis-3.4.0.jar:3.4.0]
- at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48) ~[mybatis-3.4.0.jar:3.4.0]
- at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59) ~[mybatis-3.4.0.jar:3.4.0]
- at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) ~[mybatis-3.4.0.jar:3.4.0]
- at com.sun.proxy.$Proxy96.selectUnusedPageNum(Unknown Source) ~[na:na]
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
- at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
- at com.dianping.zebra.dao.AsyncMapperProxy.invoke(AsyncMapperProxy.java:64) ~[zebra-dao-0.2.4.jar:na]
- at com.sun.proxy.$Proxy96.selectUnusedPageNum(Unknown Source) ~[na:na]
第二行是重点。点击查看代码。
- public SqlCommand(Configuration configuration, Class<?> mapperInterface, Method method) {
- String statementName = mapperInterface.getName() + "." + method.getName();
- MappedStatement ms = null;
- if(configuration.hasStatement(statementName)) { //正常的逻辑都会进入该 if 逻辑,然后得到ms。 该方法未进入该逻辑。不到是该方法初始化时,就失败了。
- ms = configuration.getMappedStatement(statementName);
- } else if(!mapperInterface.equals(method.getDeclaringClass())) {
- String parentStatementName = method.getDeclaringClass().getName() + "." + method.getName();
- if(configuration.hasStatement(parentStatementName)) {
- ms = configuration.getMappedStatement(parentStatementName);
- }
- }
- if(ms == null) {
- if(method.getAnnotation(Flush.class) == null) {
- throw new BindingException("Invalid bound statement (not found): " + statementName); //该行即为抛出的异常日志
- }
- this.name = null;
- this.type = SqlCommandType.FLUSH;
- } else {
- this.name = ms.getId();
- this.type = ms.getSqlCommandType();
- if(this.type == SqlCommandType.UNKNOWN) {
- throw new BindingException("Unknown execution method for: " + this.name);
- }
- }
- }
下面开始追踪初始化的代码块。
- public class ZebraMapperFactoryBean<T> extends SqlSessionDaoSupport implements FactoryBean<T> {
- private Class<T> mapperInterface;
- private boolean addToConfig = true;
- public ZebraMapperFactoryBean() {
- }
- public void setMapperInterface(Class<T> mapperInterface) {
- this.mapperInterface = mapperInterface;
- }
- public void setAddToConfig(boolean addToConfig) {
- this.addToConfig = addToConfig;
- }
- protected void checkDaoConfig() {
- super.checkDaoConfig();
- Assert.notNull(this.mapperInterface, "Property 'mapperInterface' is required");
- Configuration configuration = this.getSqlSession().getConfiguration();
- if(this.addToConfig && !configuration.hasMapper(this.mapperInterface)) {
- try {
- configuration.addMapper(this.mapperInterface);//下面跟进该方法查询具体的报错行
- } catch (Throwable var6) {
- this.logger.error("Error while adding the mapper '" + this.mapperInterface + "' to configuration.", var6); // 初始化时,执行到这里其实已经报错了。但是没影响启动
- throw new IllegalArgumentException(var6);
- } finally {
- ErrorContext.instance().reset();
- }
- }
- }
- public class MapperAnnotationBuilder {
- private SqlSource getSqlSourceFromAnnotations(Method method, Class<?> parameterType, LanguageDriver languageDriver) {
try {
Class<? extends Annotation> sqlAnnotationType = this.getSqlAnnotationType(method);
Class<? extends Annotation> sqlProviderAnnotationType = this.getSqlProviderAnnotationType(method);
Annotation sqlProviderAnnotation;
if(sqlAnnotationType != null) {
if(sqlProviderAnnotationType != null) {
throw new BindingException("You cannot supply both a static SQL and SqlProvider to method named " + method.getName());
} else {
sqlProviderAnnotation = method.getAnnotation(sqlAnnotationType);
String[] strings = (String[])((String[])sqlProviderAnnotation.getClass().getMethod("value", new Class[0]).invoke(sqlProviderAnnotation, new Object[0]));
return this.buildSqlSourceFromStrings(strings, parameterType, languageDriver);
}
} else if(sqlProviderAnnotationType != null) {
sqlProviderAnnotation = method.getAnnotation(sqlProviderAnnotationType);
return new ProviderSqlSource(this.assistant.getConfiguration(), sqlProviderAnnotation);
} else {
return null;
}
} catch (Exception var8) {
throw new BuilderException("Could not find value method on SQL annotation. Cause: " + var8, var8); //最初的报错的位置
}
}
这里就可以找到具体的初始化失败的方法了。
5.至此找到了,正确的解决方案。
6.由此得出几个结论。1.mybatis 报警的确是很不明确。 2.出现问题,优先还是优先考虑排除法。一段代码一段代码检查。
记一次mybatis bindingexception 问题排查的更多相关文章
- 记一次线上bug排查-quartz线程调度相关
记一次线上bug排查,与各位共同探讨. 概述:使用quartz做的定时任务,正式生产环境有个任务延迟了1小时之久才触发.在这一小时里各种排查找不出问题,直到延迟时间结束了,该任务才珊珊触发.原因主要就 ...
- 记一笔MyBatis的坑
记一笔MyBatis的坑 1.sql查询concat()连接函数xml运行查询乱码 ) , ), char)'%') bll FROM fact_dkxx sq 由于连接的字符串中包含数字与百分比字符 ...
- 解Bug之路-记一次存储故障的排查过程
解Bug之路-记一次存储故障的排查过程 高可用真是一丝细节都不得马虎.平时跑的好好的系统,在相应硬件出现故障时就会引发出潜在的Bug.偏偏这些故障在应用层的表现稀奇古怪,很难让人联想到是硬件出了问题, ...
- 记自己在mybatis中设置jdbcType的一个坑
项目是用ssm搭建的.主要是为app数据接口.其中有一个需求就app想要查询一段时间内某个用户的测量信息,所以app给我后端传递了3个参数,分别是appuserId(String),startDate ...
- mybatis BindingException: Invalid bound statement (not found)
错误截图 解决措施 此异常的原因是由于mapper接口编译后在同一个目录下没有找到mapper映射文件而出现的. 通常我们在配置SqlSessionFactory时会有如配置 <!-- 配置Sq ...
- 记一次MyBatis的错误
错误信息:java.lang.StackOverflowError 关于这个错误的深度解析,大家可以参考这篇博文,比较详细:https://blog.csdn.net/zc375039901/arti ...
- 记一次mybatis<if>标签的问题
前言 到底还是没理解清楚的锅~~~~搞了好久...啊啊啊啊 错误: There is no getter for property named 'name' in 'class java.lang.L ...
- Kafka 异步消息也会阻塞?记一次 Dubbo 频繁超时排查过程
线上某服务 A 调用服务 B 接口完成一次交易,一次晚上的生产变更之后,系统监控发现服务 B 接口频繁超时,后续甚至返回线程池耗尽错误 Thread pool is EXHAUSTED.因为服务 B ...
- 记一次node节点异常排查
一.背景 公司进行kubernetes服务重启演练,集群重启后所有服务正常,仅node2节点处于notready状态 二.排查过程 查看对应节点的详细信息,发现kubelet一直处于starting状 ...
随机推荐
- CentOS 7下 部署Redis-cluster集群
redis集群是一个无中心的分布式redis存储架构,可以在多个节点之间进行数据共享,解决了redis高可用.可扩展等问题,redis集群提供了以下两个好处:1)将数据自动切分(split)到多个节点 ...
- springboot自动生成mysql的DAO层代码
springboot提供了强大丰富的整合内容,但是每次要写一堆dao层的xml或者数据库相关的配置代码的时候,还是挺繁琐又容易出错的. 可以用mybatis-generator自动生成代码: 只需要加 ...
- 《ASP.NET Core In Action》读书笔记系列四 创建ASP.NET Core 应用步骤及相应CLI命令
一般情况下,我们都是从一个模板(template)开始创建应用的(模板:提供构建应用程序所需的基本代码).本节使用 Visual Studio 2017 .ASP.NET Core2.0和 Visua ...
- 转载 usb_alloc_coherent 和 usb_free_coherent
今天做移植的时候,随手记录一下,今天所遇到的问题解决方法. 在linux2.6.34和之前的代码中还可以使用usb_buffer_alloc 和 usb_buffer_free 这两个函数,在2.6. ...
- python locust 性能测试:嵌套
TaskSet类和TaskSequence类可用于嵌套<可以在TaskSequences中嵌套TaskSets,反之亦然>: from locust import TaskSet, tas ...
- 简单快速部署nexus3私服
本文适用范围:用户规模不大,不需要考虑maven仓库负载均衡的群体. 为何部署nexus3 之前由于懒某些原因,所有开发人员自己定义.m2的settings,大多使用ali提供的maven仓库,但是最 ...
- zigbee 中ZDO的理解
---恢复内容开始--- ZigBee 物理层:主要进行无线数据的收发,同时定义了无线传输的信道以及频率. MAC层:使用CSMA-CA机制接入到无线信道,负责传输信标帧,保持同步和 ...
- JDK源码分析(12)之 ConcurrentHashMap 详解
本文将主要讲述 JDK1.8 版本 的 ConcurrentHashMap,其内部结构和很多的哈希优化算法,都是和 JDK1.8 版本的 HashMap是一样的,所以在阅读本文之前,一定要先了解 Ha ...
- phtyon
https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014316399410395 ...
- js之数组操作
js之数组操作 前言 本文主要从应用来讲数组api的一些操作,如一行代码扁平化n维数组.数组去重.求数组最大值.数组求和.排序.对象和数组的转化等.(文章摘自:https://segmentfault ...