首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >踩坑实录|mybatis项目报错:...Exception: Type interface UserMapper is not known to the MapperRegistry

踩坑实录|mybatis项目报错:...Exception: Type interface UserMapper is not known to the MapperRegistry

作者头像
知识分子没文化
发布2023-07-01 15:44:36
发布2023-07-01 15:44:36
2.1K0
举报
文章被收录于专栏:Roookie博客Roookie博客

环境说明: 系统:win10 专业版 开发环境:IDEA JDK版本:1.8 mysql:5.5 mybatis:3.5.3 Junit:5.7.0

问题再现:

mybatis项目运行时报错,报错信息如下:

代码语言:javascript
复制
org.apache.ibatis.binding.BindingException: Type interface com.langp.dao.UserMapper is not known to the MapperRegistry.

    at org.apache.ibatis.binding.MapperRegistry.getMapper(MapperRegistry.java:47)
    at org.apache.ibatis.session.Configuration.getMapper(Configuration.java:779)
    at com.langp.dao.UserMapperTest.getUserList(UserMapperTest.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:498)
    ·····

Process finished with exit code -1

错误原因:

报错信息中出现了Type interface com.langp.dao.UserMapper is not known to the MapperRegistry,简单翻译一下就是:类型接口com.langp.dao.UserMapper不为MapperRegistry所知

所以这个错误肯定是与mapper有关系的。每一个Mapper.xml都需要在mybatis核心配置文件中进行注册,由于mybatis的核心配置文件mybatis-config.xml中缺少对应接口的Mapper.xml,所以运行时就会报错。

解决方法:

在mybatis的核心配置文件中添加如下内容:

代码语言:javascript
复制

其中,resource属性的值是接口对应Mapper.xml文件。添加之后即可解决。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题再现:
  • 错误原因:
  • 解决方法:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档