Mybatis:Type interface com.itheima.dao.IUserDao is not known to the MapperRegistry.解决方案

项目场景

最近,在跟着黑马IT的视频学习mybatis,现记录如下

开发环境描述

IDEA版本:20201.1
JDK版本:jdk1.8.0_181、jdk-14.0.2、jdk-16.0.1
Maven版本:apache-maven-3.5.2

该问题出现在以上版本,并成功解决。

问题描述

出现报错:Type interface com.itheima.dao.IUserDao is not known to the MapperRegistry.

image-20220207162607830

解决方案

核对 SqlMapConfig.xml 中信息径发现并无异常,最终发现自己的 namespace 写错了。

image-20220207162743496

修改 namespace

image-20220207163918126

再次运行,成功解决

image-20220207163940371

原因分析

一般出现 Type interface com.itheima.dao.IUserDao is not known to the MapperRegistry. 异常时,我们应该安装以下步骤进行排查:

  1. 检查 SqlMapConfig.xml 中有没有配置 mapper 路径
  2. 检查 SqlMapConfig.xmlresource 指定位置是都有误
  3. 检查路径中的 namespace 是否配置错误

其他可能出现的错误

需要注意,如果报错是org.apache.ibatis.exceptions.PersistenceException:### Error querying database. 需要根据后面的 Cause:xxx来判断错误类型

resultType 配置错误的话,会报 Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating interface com.itheima.dao.IUserDao with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.itheima.dao.IUserDao.<init>() 异常

sql语句错误的话,会报 Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'eesy_mybatis.usr' doesn't exist 异常

参考文献

1.Mybatis:Type interface com.itheima.dao.IUserDao is not known to the MapperRegistry.解决方案

写在后面

欢迎随时留言讨论,知无不答!

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值