关于Type interface mapper.UserMapper is not known to the MapperRegistry.问题

最近正在学习Mybatis-Spring的使用方法,今天第一次尝试直接使用Spring来整合mybatis配置(包括数据源设置,mapper映射等等)将sqlSessionFactory以及sqlSession全部交由Spring进行管理。在这个过程中遇到了如题所示的问题,参考了网络中的方法并且自己进行了一些探索,终于是解决了这个问题。

Type interface mapper.UserMapper is not known to the MapperRegistry

在说这个问题之前,我也强调一下在碰到这个问题之前可能遇到的一系列问题:

  • 资源导出的问题
    使用maven开发有着比较严格的打包方式,可能有小伙伴会和我一样配置文件与java文件混合在一个包下(习惯不好~~),如下图:

    在这种情况下你可能会发现你的代码以及文件格式完全没有问题但是怎么也无法让程序顺利地执行下去,这时候可以检查一下我们的target文件夹,查看一些必要的资源是否都已经成功导出:

    如果结果如上图所示(重要资源文件都已经成功导出,且位置信息正确无误),那么恭喜你可以进入下一步的检查工作。
    但如果你发现导出的结果并不如你所料那么大概率是资源导出的问题,这时候我们可以在maven的配置文件中进行build配置:(示例代码)
    <!--防止资源导出失败--><build><resources><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build>
  • applicationContext.xml的配置问题
    在使用Spring进行mybatis的代理时,很重要的一步是将重要的库类注册到Spring仓库中,当然也包括对mapper信息的注册:
    <!--使用spring进行SqlSessionFactory的配置--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="datasource"/><!--进行mybatis的配置设置,事实上在spring中就可以完全代替原来的mybatis-config.xml配置文件--><!--configLocation进行一个绑定操作,表明mybatis-config.xml中的配置信息也会使用--><property name="configLocation" value="mybatis-config.xml"/><!--mapperLocation即原来mybatis配置文件中的mapper映射--><property name="mapperLocations" value="classpath:mapper/*.xml"/></bean>

当然对Spring的mybatis配置不熟悉的朋友,可以尝试在原来的mybatis-config.xml中使用mapper标签进行配置,对比试验:如果发现错误消除,那么很有可能是配置填写的错误,可以反过头来再仔细查看。

我这里还提供一个小方法用以确认资源导入是否正确,这也是最直观最便捷的方式:通过debug来确定,一下是简介

我们可以在临近出错的位置打上断点,接着找到对应的mapperRegister,也就是题目中错误信息的最终来源,来查看我们的配置信息是否已经成功注入:


在“knownMappers”下我们可以看到已经被成功识别的各个Mapper信息(图中表示为已成功识别的情况,如果没有成功,那么你所需要的Mapper信息是缺失的)

  • 路径以及格式问题(最坑爹的~~~~)
    其实不单是mybatis,很多的配置类文件都对格式有着严格的要求,如果不仔细观察,它很有可能站在你面前你都不知道它就是罪魁祸首,相信很多人和我一样,碰到过“.”与“/”的疑惑,惭愧的是我依然很难分清楚两者的主要使用场景。
    在***mapper.xml文件中,有一个必不可少的信息是“namespace”(可能很多同学就是忘了namespace)

    除了它存在的必要性以外,还有重要的一点是它的格式,首先需要注意的是必须指明其文件路径(如图中如果直接写UserMapper则会出现题目中的错误信息),除此以外还有必须注意其需要使用“.”格式来指明接口。

以上则为本人对题目中问题的小结。本人是新手一枚,如果有错误希望大家可以提出来,感谢!!

关于Type interface mapper.UserMapper is not known to the MapperRegistry.问题相关推荐

  1. Type interface mapper.UserMapper is not known to the MapperRegistry

    Type interface mapper.UserMapper is not known to the MapperRegistry. 报错:Type interface mapper.UserMa ...

  2. Mybatis注解开发出现Type interface Mapper.StudentMapper is not known to the MapperRegistry异常解决办法

    Mybatis注解开发出现Type interface Mapper.StudentMapper is not known to the MapperRegistry异常解决办法 在核心配置文件中,配 ...

  3. Mybatis项目错误:Type interface dao.UserMapper is not known to the MapperRegistry.

    检查mybatis-config.xml文件,将 <mappers><package name="mappers/UserMapper.xml"/> < ...

  4. 解决Type interface com.kuang.mapper.UserMapper is not known to the MapperRegistry.的问题

    解决Type interface com.kuang.mapper.UserMapper is not known to the MapperRegistry.的问题 错误代码: 二月 13, 202 ...

  5. Type interface com.mybatis.mapper.UserMapper is not known to the MapperRegistry

    Type interface com.mybatis.mapper.UserMapper is not known to the MapperRegistry报错信息 出现了这个问题一般是因为myba ...

  6. SpringBoot出错:Consider defining a bean of type ‘com.mapper.UserMapper‘

    SpringBoot出错:Consider defining a bean of type 'com.mapper.UserMapper' com.service.impl中的userMapper字段 ...

  7. mybatis报错Type interface xxx.Dao is not known to the MapperRegistry

    今天在做mybatis的时候,遇到一个错误,大家看看这个错误吧:org.apache.ibatis.binding.BindingException: Type interface cn.mybati ...

  8. Type interface com.mybatis.mapper.UserMapper is not known to the MapperRegistry. 解决方法

    我错误的找了很多文章都没说到点子上,因为我的映射文件是放在resources文件夹下面, 但是我在引入映射文件的时候是 <mappers><mapper class="ma ...

  9. Type interface xxx.XxxMapper is not known to the MapperRegistry解决方案

    最近学SSM框架学到MyBatis时出现如题报错 上网搜一圈发现大部分两个原因: 1.config.xml文件中的Mapper中内容写错了 2.Mapper.xml文件中的namespace内容写错了 ...

最新文章

  1. Vue.js 数据绑定渲染Demo
  2. ArcGIS制图之Sub Points点抽稀
  3. String、StringBuilder、StringBuffer的比较
  4. ccna第四学期final一二三套题
  5. 如何让你的webapp也能跳窗口搜索
  6. elf section类型_在 498 行极小 OS 上跑标准 ELF 程序
  7. 什么是SVC模式【转】
  8. Spring Bean Scope 有状态的Bean 无状态的Bean
  9. wordpress添加html媒体文件,WordPress“添加媒体”文件时只显示上传到当前文章的附件图片...
  10. 5006.c++类中使用static变量bug
  11. 关于MARATHON和容器的端口映射
  12. 如何零成本录制一首单人ACAPPELLA
  13. 计算机考试感受作文,关于考试后的感想作文(精选10篇)
  14. assert:python断言报错语句
  15. python学习感悟
  16. 计算机图解教程视频教程,新手怎么制作短视频教程?视频处理的图文步骤
  17. HTML图片不能上下铺满屏幕_多张图片的PPT,如何排版的更有创意?
  18. 拉格朗日四平方和定理c语言,拉格朗日四平方定理的证明
  19. 针对safecast数据集的数据清洗
  20. 智慧(灯杆)路灯建设有可能会掀起城市革命,从而点亮新型智慧城市

热门文章

  1. FPGA远程固件在线升级
  2. C语言while循环中逗号表达式的用法(以及怎么读入引号中有空格的字符串!!!)
  3. kubernetes 联邦搭建(kubefed)
  4. 乡村少年宫计算机小组活动教案,乡村少年宫电脑绘兴趣小组教案.doc
  5. Java入门(五)-开发工具IntelliJ IDEA
  6. [原创]Woden的艰辛找工历程
  7. 揭秘把火锅店变成银行,收款500万!金融轻松赚钱的商业模式!
  8. js对象、数组对象根据属性值进行升序降序排序
  9. iOS底层原理班(下)/OC对象/关联对象/多线程/内存管理/性能优化-李明杰-专题视频课程...
  10. 在中国,生态是不是个伪命题?