错误描述

Caused by: org.apache.ibatis.builder.IncompleteElementException: Could not find result map xxxxxxx

结论

  1. 因为资源加载顺序违反resultMap节点的继承顺序,导致一些resultMap没有解析
  2. 解决方式:单独重新配置,使其重新解析一次

错误分析

  1. 定位报错位置(由于公司代码不方便截图)
    1.1 通过报错堆栈发现是dao层调用时触发
    (1)mybatis通过代理执行逻辑(MapperProxy#invoke)
    (2)主要关注MapperMethod mapperMethod = cachedMapperMethod(method);


    (3)继续关注XMLStatementBuilder#parseStatementNode --> MapperBuilderAssistant#addMappedStatement方法


    (3) 最终定位到从config中没有获取到值,所以抛出异常
  2. 为什么config里没有值?是没有解析吗?
    2.1 config是什么?见下方红色标记

    2.2 resultMap节点解析后是怎么放入config中的?


    2.3 当resultMap节点中包含extend属性,但是在config中没有,则抛出异常(最终忽略),将未解析成功resultMapResolver添加config的incompleteResultMaps属性中

    2.4 每解析完一个xml文件后,都会将之前未解析成功再次尝试解析


    2.5 综上所述,有可能extend加载顺序的问题导致有些resultMap节点没有解析成功
    (1)譬如 xxVo 继承 xxPo 继承 xxEnt,而恰好也是最后几个被解析的文件
  3. 为什么IDEA启动成功,但jar方式启动报错?
    3.1 怎么对比其中的差异性?
    (1)在Jar包启动时加入参数:-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
    (2)IDEA以远程debug方式启动
    3.2 通过对比发现,IDEA以本地文件方式加载,而jar包读取Jar方式加载,读取协议不一样

    (1)获取指定表达式的资源根路径(2个jar包或者2个模块)



    (2)两种启动方式对应两种协议

    3.2 通过debug代码发现jar包加载没有按照包的层级加载导致了问题

补充

由于对jar包方式加载资源感兴趣,单独拉出来代码

public class JarResoureLoaderTest {@Testpublic void test() throws IOException {String mapperLocation = "classpath*:com/coe/cdcs/**/xml/**/*.xml";String rootDirPath = "classpath*:com/coe/cdcs/";String subPattern = "**/xml/**/*.xml";String path = "com/coe/cdcs/";Resource[] rootDirResources = getResources(path);Set<Resource> result = new LinkedHashSet<>(16);for (Resource rootDirResource : rootDirResources) {URL rootDirUrl = rootDirResource.getURL();if(ResourceUtils.isJarURL(rootDirUrl)){result.addAll(doFindPathMatchingJarResources(rootDirResource,rootDirUrl,subPattern));}}Resource[] mappers = result.toArray(new Resource[0]);}private Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource,URL rootDirURL,String subPattern) throws IOException {URLConnection con = rootDirURL.openConnection();JarFile jarFile = null;String jarFileUrl;//com/coe/cdcs/String rootEntryPath = null;boolean closeJarFile = false;if (con instanceof JarURLConnection) {JarURLConnection jarCon = (JarURLConnection) con;ResourceUtils.useCachesIfNecessary(jarCon);jarFile = jarCon.getJarFile();jarFileUrl = jarCon.getJarFileURL().toExternalForm();JarEntry jarEntry = jarCon.getJarEntry();rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");closeJarFile = !jarCon.getUseCaches();}/*** 1. jar:file:/C:/Users/zhangjie/Desktop/出口组异常纪录/cdcs-admin-0.0.2-SNAPSHOT.jar!/BOOT-INF/classes*   1.1 第一次entryPath 为 "com/"* 2. result添加顺序有误(重点)*/try{Set<Resource> result = new LinkedHashSet<>(8);for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {PathMatcher pathMatcher = new AntPathMatcher();JarEntry entry = entries.nextElement();String entryPath = entry.getName();if (entryPath.startsWith(rootEntryPath)) {//相对路径String relativePath = entryPath.substring(rootEntryPath.length());//subPattern = **/xml/**/*.xml  -->判断相对路径是否符合正则if(pathMatcher.match(subPattern,relativePath)){result.add(rootDirResource.createRelative(relativePath));}}}return result;}finally {if (closeJarFile) {jarFile.close();}}}private Resource[] getResources(String rootDirPath) throws IOException{// admin和core包都包含com/coe/cdcs/Set<Resource> result = new LinkedHashSet<>(16);ResourceLoader resourceLoader = new DefaultResourceLoader();ClassLoader cl = resourceLoader.getClassLoader();Enumeration<URL> resourceUrls = cl.getResources(rootDirPath);while(resourceUrls.hasMoreElements()){URL url = resourceUrls.nextElement();Resource resource = new UrlResource(url);result.add(resource);}Resource[] rootDirResources = result.toArray(new Resource[0]);return rootDirResources;}
}

mybatis分析-IncompleteElementException: Could not find result map相关推荐

  1. mybatis异常:Could not find result map ......... 问题分析及解决

    mybatis异常:Could not find result map ......... 问题分析及解决 参考文章: (1)mybatis异常:Could not find result map . ...

  2. mybatis异常:Could not find result map Java.util.Map 问题分析及解决 定位不到具体的位置的错误

    mybatis异常:Could not find result map Java.util.Map 问题分析及解决 定位不到具体的位置的错误 参考文章: (1)mybatis异常:Could not ...

  3. org.apache.ibatis.builder.IncompleteElementException: Could not find result map ‘ com.rocship.genera

    org.apache.ibatis.builder.IncompleteElementException: Could not find result map ' com.rocship.genera ...

  4. org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.zjj.dao.UserDao.

    org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.zjj.dao.UserDao. ...

  5. mybatis异常:Could not find result map Java.util.Map 问题分析及解决

    使用mybatis时,自己或者同事踩到的坑给大家分享下,有其他问题分享的同学欢迎交流~ 现象:编译未出现异常,调用相关服务时候,出现 Could not find result map Java.ut ...

  6. [mybatis异常:Could not find result map ......]

    问题描述:编写mybatis时出现异常,显示找不到这个结果集, 解决办法: 原因:我们传出的结果不是一个集或者说,我们规定他传出的是一个类,完美解决

  7. Mybatis报错:Could not find result map

    四月 08, 2018 9:00:19 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() fo ...

  8. mybatis报错(三)报错Result Maps collection does not contain value for java.lang.Integer解决方法...

    转自:https://blog.csdn.net/zengdeqing2012/article/details/50978682 1 [WARN ] 2016-03-25 13:03:23,955 - ...

  9. myibatis 报错 Could not find result map java.util.HashMap

    mybatis异常:Could not find result map Java.util.Map 问题分析及解决 错误写法   <select id="queryXXXCount&q ...

最新文章

  1. C++运行时类型信息 (RTTI)
  2. Source引擎的远程代码执行漏洞,可能影响千万游戏玩家
  3. MapReduce基础开发之五分布式下载ftp文件到本地再迁移到hdfs
  4. spyder的输出面板不小心关掉了怎么办?
  5. 软件工程基础-结对项目-WordCount(单词计数)
  6. HTTP 错误 403.6 - Forbidden 解决方案
  7. FVC与地表温度的相关性分析研究
  8. 树莓派 树莓派 编c++_如何建立一个树莓派冰箱的冷冻监视器
  9. 毕业设计,管理系统,大学生毕业设计应该这么做
  10. 超震惊!!微软产品经理每天的工作内容竟然是这个...
  11. Vue-跟着李南江学编程
  12. 严小样儿教你做数据分析(1)——Excel做一元线性回归预测和相关系数计算
  13. WordPress美女图集COS写真整站自适应源码带完整数据
  14. Charles修改ip
  15. SSTI 模板注入url_for和get_flashed_messages之[WesternCTF2018]shrine
  16. 【解题报告】2021牛客寒假算法基础集训营4
  17. 【笔记篇】11仓管系统WCS系统——之《实战供应链》
  18. python中pandas处理csv_python – 处理pandas的问题读取csv
  19. 华北电力大学计算机专业学什么,华北电力大学计算机专业复试科目都是什么?...
  20. 《那些年啊,那些事——一个程序员的奋斗史》——93

热门文章

  1. 中投民生:今日A股大面积飘绿;注册制独领风骚
  2. 第15章 位图和Bitblt
  3. PowerDesigner 窗口字体太小,调整
  4. 模版的分离编译 解决方案
  5. html显示立方米符号,怎么打立方米符号m³ 打出m³立方米符号的方法
  6. android-RecyclerView浅谈
  7. Windows和夜神模拟器上抓包程序mitmproxy的安装以及使用
  8. 例说数学学习中的四基
  9. 装修鸿蒙瓷砖选择,瓷砖有必要买贵的吗?建材老板说出真相:便宜也能买到好瓷砖...
  10. 人工智能识别植物准确率高达80% 植物学家轻松了