今天按照视频来一步一步敲完之后,发现程序没有办法识别注解文件在哪个位置
但是我在mybatis核心配置文件中,已经说明了接口文件所在位置了,困扰了很久,最后终于找到答案;

<!--    指定接口所在位置--><mappers><package name="com.dao.UserDao"/></mappers>

在核心配置文件中已经声明;

再看测试类中的启动代码

    public static void main(String[] args) throws IOException {InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);//非常需要注意下面这一行代码,用来注册注解文件// factory.getConfiguration().addMapper(UserDao.class);SqlSession sqlSession = factory.openSession();UserDao userDao = sqlSession.getMapper(UserDao.class);List<User> users = userDao.findAll();for ( User user : users){System.out.println(user);}sqlSession.close();inputStream.close();}

这是原来的启动文件,使用它就会爆出错误:

log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.apache.ibatis.binding.BindingException: Type interface com.dao.UserDao 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:745)at org.apache.ibatis.session.defaults.DefaultSqlSession.getMapper(DefaultSqlSession.java:292)at com.MybatisTest.main(MybatisTest.java:29)Process finished with exit code 1

原来必须要添加上这一行代码:!!!!!!!!!
factory.getConfiguration().addMapper(UserDao.class);
用来注册注解文件

即:

    public static void main(String[] args) throws IOException {InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);factory.getConfiguration().addMapper(UserDao.class);SqlSession sqlSession = factory.openSession();UserDao userDao = sqlSession.getMapper(UserDao.class);List<User> users = userDao.findAll();for ( User user : users){System.out.println(user);}sqlSession.close();inputStream.close();}

最终成功运行:

log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
User{id=41, username='老王', birthday=Tue Feb 27 17:47:08 CST 2018, sex='男', address='北京'}
User{id=42, username='小二王', birthday=Fri Mar 02 15:09:37 CST 2018, sex='女', address='北京金燕龙'}
User{id=43, username='小san王', birthday=Sun Mar 04 11:34:34 CST 2018, sex='女', address='北京金燕龙'}
User{id=45, username='传智播客', birthday=Sun Mar 04 12:04:06 CST 2018, sex='男', address='北京金燕龙'}
User{id=46, username='老王', birthday=Wed Mar 07 17:37:26 CST 2018, sex='男', address='北京'}
User{id=48, username='小马宝莉', birthday=Thu Mar 08 11:44:00 CST 2018, sex='女', address='北京修正'}
User{id=54, username='nananna', birthday=Sat Aug 21 18:29:06 CST 2021, sex='n', address='666'}
User{id=55, username='nananna', birthday=Sun Aug 29 12:40:45 CST 2021, sex='n', address='666'}Process finished with exit code 0

mybatis使用注解的时候,找不到映射:Type interface com.dao.UserDao is not known to the MapperRegistry.相关推荐

  1. Mybatis错误:Type interface com.dao.UserDao is not known to the MapperRegistry.

    1.编写简单的mybatis架构后,运行显示出现错误:Type interface com.dao.UserDao is not known to the MapperRegistry. 2.添加my ...

  2. Type interface com.haroro.dao.UserDao is not known to the MapperRegistry——MyBatis问题

    初学MyBatis的时候,往往出现的错误都是一些细节上引起的.今天就遇到了一个问题,在运行测试类的时候,出现了以下的错误提示: org.apache.ibatis.binding.BindingExc ...

  3. mybatis错误:Type interface com.sks.dao.UserDao is not known to the MapperRegistry.

    mybatis错误org.apache.ibatis.binding.BindingException: Type interface com.sks.dao.UserDao is not known ...

  4. mybatis报错Type interface xxx.Dao is not...

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

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

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

  6. MyBatis报错:org.apache.ibatis.binding.BindingException: Type interface com.smbms.dao.provider.Provider

    在Java使用MyBatis框架开发时,遇到报错:org.apache.ibatis.binding.BindingException: Type interface com.smbms.dao.pr ...

  7. Mybatis报错org.apache.ibatis.binding.BindingException: Type interface com.trf.dao.UserDao is not known

    报错log:org.apache.ibatis.binding.BindingException: Type interface com.trf.dao.UserDao is not known to ...

  8. @param注解_启用 parameters 编译选项简化 mybatis @Param 注解重复问题

    在使用 mybatis 查询的时候, 只需要定义一个查询接口, mybatis 会为我们注入注解实现或是 xml 实现. 但当我们需要传递参数时, 通常需要 @Param 来定义一个名称, 但经常的, ...

  9. Mybatis @Flush注解分析

    Mybatis @Flush注解分析 在看源码的的时候,发现了@Flush注解.之前没用过,于是就有了这篇文章 注意:这里的执行器的类型肯定是BatchExecutor 先来例子 @Testpubli ...

  10. mybatis使用注解开发

    mybatis使用注解开发 面向接口编程 在之前我们是通过面向对象编程,但是在真正开发的时候我们会选择面向接口编程. 根本原因 : 解耦 , 可拓展 , 提高复用 , 分层开发中 , 上层不用管具体的 ...

最新文章

  1. Rocksdb 的 rate_limiter实现 -- compaction限速
  2. 用JS获取地址栏参数的方法
  3. LeetCode 1073. 负二进制数相加(负数进制)
  4. 价值50万年薪的Java面试题
  5. 吃货的第一要诀 | 在马来西亚这么吃才爽!
  6. 怎样使用计算机上的高级共享设置,win7打印机共享怎么设置
  7. python爬虫工程师工作内容_爬虫岗位职责
  8. python根据服务器sn号查询DELL服务器型号、出厂时间、过保时间
  9. linux环境模拟器,在Linux环境下玩PlayStation模拟器
  10. Thermal_Config_Tool_exe_v1使用
  11. Cache tier使用文档
  12. 今日杂谈---重用和程序员
  13. 项目管理论坛_活动预告|2019年“VUCA时代项目管理与项目治理”论坛通知
  14. 驼峰式命名法python_驼峰命名法
  15. Linux修改fstab引起系统无法启动问题的解决方法
  16. 论文里引用专利参考文献怎么写?
  17. Spring Cloud Alibaba x AppActive 带来的全新异地活动解决方案
  18. 量化投资学习——经济周期
  19. GPS北斗模块串口助手输出测试
  20. element-ui 上传图片后清空图片显示

热门文章

  1. aardio修改图标
  2. [数据挖掘笔记] KMeans豆瓣文本聚类
  3. 服务器 sn 作用,命令查看服务器SN号
  4. SVN :找不到这样的主机
  5. Hero image网站转化这么高?21个最佳案例给你参考
  6. C++程序设计的技巧-Pimple的使用
  7. 怎么打开产品原型是html,如何打开产品原型图(axure)
  8. ubuntu下向163发送邮件
  9. 大数据技术领域介绍及学习方法和发展规划
  10. 农夫山泉推出新品矿泉水“长白雪”域名表现如何?