Mybatis报错:Could not find resource mybatis-conf.xml

报错截图:

报错内容:

java.io.IOException: Could not find resource mybatis-conf.xml

	at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114)
at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100)
at org.apache.ibatis.io.Resources.getResourceAsReader(Resources.java:160)
at MybatisAdvancedTest.testQueryByNo(MybatisAdvancedTest.java:23)

CSDN上jeanFlower在文章说这是IDEA默认不编译src目录下的xml文件造成的(在后面也贴出他的解决办法),而我的mybatis-config.xml文件时在resources目录下,Debug进去观看流程发现Resources.getResourceAsReader根本没有加载到这个xml配置文件.

代码示意:

    // 根据学号查询一个学生
@Test
public void testQueryByNo() throws IOException {
String resource = "mybatis-conf.xml";
Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sessionFactory
= new SqlSessionFactoryBuilder().build(reader);
SqlSession session = sessionFactory.openSession(); //传入StudentMapper接口,返回该接口的mapper代理对象studentMapper
StudentMapper studentMapper = session.getMapper(StudentMapper.class);//接口 //通过mapper代理对象studentMapper,来调用IStudentMapper接口中的方法
Student student = studentMapper.queryStudentByNo(1); System.out.println(student+"****");
session.close();
}

解决办法:

将上面的Test方法中这部分代码进行替换:

    String resource = "mybatis-conf.xml";
Reader reader = Resources.getResourceAsReader(resource);

替换成:

	Reader reader = Resources.getResourceAsReader("mybatis-conf.xml");

原因暂时未知,明天Debug更新

如果是xml未被idea正常编译的问题,例如IDEA开发,但是没有将mybatis-config.xml放在resources目录下,例如放在src/main/java下,那么在pom.xml末尾添加build代码,告诉idea对我们的配置文件进行编译:

解决方案二

<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>

解决方案三

将配置文件移到resources目录下,rebuild我们的项目.

Mybatis报错:Could not find resource mybatis-conf.xml的更多相关文章

  1. mybatis报错Mapped Statements collection does not contain value for com.inter.IOper

    首页 > 精品文库 > mybatis报错Mapped Statements collection does not contain value for com.inter.IOper m ...

  2. mybatis报错:Invalid bound statement (not found)

    mybatis报错:Invalid bound statement (not found)的原因很多,但是正如报错提示一样,找不到xml中的sql语句,报错的情况分为三种: 第一种:语法错误 Java ...

  3. Springboot项目下mybatis报错:Invalid bound statement (not found)

    mybatis报错:Invalid bound statement (not found)的原因很多,但是正如报错提示一样,找不到xml中的sql语句,报错的情况分为三种: 第一种:语法错误 Java ...

  4. Mybatis 报错

    Mybatis 报错 builder.BuilderException: Error parsing SQL Mapper Configuration Caused by: org.apache.ib ...

  5. 解决Mybatis 报错Invalid bound statement (not found)

    解决Mybatis 报错Invalid bound statement (not found) 出现此错误的原因 1.xml文件不存在 2.xml文件和mapper没有映射上 namespace指定映 ...

  6. mybatis报错 Error instantiating interface com.atguigu.mybatis.dao.DepartmentMapper with invalid types () or values ()

    mybatis报错 Error instantiating interface com.atguigu.mybatis.dao.DepartmentMapper with invalid types ...

  7. SpringBoot使用MyBatis报错:Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL)

    © 版权声明:本文为博主原创文章,转载请注明出处  1. 错误描述 使用SpringBoot集成MyBatis框架,并且使用 mapper-spring-boot-starter 自动生成MyBati ...

  8. oracle+mybatis报错:BindingException("Invalid bound statement (not found): ")

    oracle+mybatis报错:BindingException("Invalid bound statement (not found): ") 从mysql转到oracle数 ...

  9. mybatis报错:A query was run and no Result Maps were found for the Mapped Statement、、Property [login_ip] not found on type [com.thinkgem.jeesite.common.permission.entity.PremissUser]问题解决

    今天在做ssm项目的时候出现了: 先是出现 了错误: mybatis报错:A query was run and no Result Maps were found for the Mapped St ...

随机推荐

  1. 数据库SQL调优的几种方式 EFcore读的情况下使用 AsNoTracking非跟踪查询

    不要用GUID 当主键 没有规律 可以用雪花ID DBA 优化法则 硬件资源是根本,DBA是为了充分利用硬件资源 一般清空下可以不使用外键 可以提高性能 合理使用临时表 临时表分页; 一些查询语句加w ...

  2. 学习一下 SpringCloud (二)-- 服务注册中心 Eureka、Zookeeper、Consul、Nacos

    (1) 相关博文地址: 学习一下 SpringCloud (一)-- 从单体架构到微服务架构.代码拆分(maven 聚合): https://www.cnblogs.com/l-y-h/p/14105 ...

  3. [从源码学设计]蚂蚁金服SOFARegistry 之 LocalDataServerChangeEvent及数据同步

    [从源码学设计]蚂蚁金服SOFARegistry 之 LocalDataServerChangeEvent及数据同步 目录 [从源码学设计]蚂蚁金服SOFARegistry 之 LocalDataSe ...

  4. java中给多个微信好友自动发信息

    package weixin; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatrans ...

  5. (数据科学学习手札101)funcy:Python中的函数式编程百宝箱

    本文示例文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 我们在使用Python完成日常任务时,经常会遇到 ...

  6. Java学习日报7.17

    控制台运行

  7. .NET Core学习笔记(8)——Entity Framework Core之Database First

    曾经我以为再也不会去弄啥Database First,然鹅我错了.这个世界上就是有啪啪打脸和真香的时候.当小伙伴拿着做好的DB表结构和SQL脚本递过来的时候,我知道我没法拒绝.望着他突起的肱二头肌和充 ...

  8. 一台PC端安装多店仓信息的删除

    如图所示,安装了多店仓,想要删除其中莫一店仓信息! 步骤一:先找到对应目录,一般默认的目录为C:\Users\xxxx\AppData\Roaming\WebPos2.0\bosnatweiniman ...

  9. FTP服务器的搭建和使用(centos7)

    1.显示如下图则表示已安装vsftp软件 如过没有则可以通过yum源进行安装 yum install -y vsftpd 操作:service vsftpd start|stop|restart 2. ...

  10. 五、Zookeeper、Hbase集群搭建

    一.前提 1.安装JDK 2.安装Hadoop 3.安装zoookeeper 1.加入zookeeper包,并解压tar -zxvf zookeeper-3.4.9.tar.gz 2.去/etc/pr ...