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. Python——元组的基本语法(创建、访问、修改、删除)

    Python 元组的使用 Python 的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号 ( ),列表使用方括号 [ ]. 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可 ...

  2. Java安全之Shiro 550反序列化漏洞分析

    Java安全之Shiro 550反序列化漏洞分析 首发自安全客:Java安全之Shiro 550反序列化漏洞分析 0x00 前言 在近些时间基本都能在一些渗透或者是攻防演练中看到Shiro的身影,也是 ...

  3. Core3.0发布到IIS的流程

    前言 参考链接 https://www.cnblogs.com/wutongjun/p/11981798.html 在IIS上部署 .Net Core 3.0 项目的主要流程有: 安装并启用IIS 安 ...

  4. @Autowired 和@Resource区别

    二者都可以用在bean的注入时,但是@Autowired是spring提供的注解,而@Resource是javax包中的. 默认情况下,@Autowired注入规则是byType,通过类型注入:当然, ...

  5. java实现读取excel文件内容

    package excel; import java.io.FileInputStream; import java.io.InputStream; import java.text.SimpleDa ...

  6. Mybatis 动态sql if 判读条件等于一个数字

    在Mybatis中 mapper中 boolean updateRegisterCompanyFlag(@Param(value = "companyId") String com ...

  7. jsp中将一个jsp引入另一个jsp指定位置

    <jsp:include page="badSurveyUpdate.jsp"/>

  8. 使用sqoop将mysql数据导入到hive中

    首先准备工具环境:hadoop2.7+mysql5.7+sqoop1.4+hive3.1 准备一张数据库表: 接下来就可以操作了... 一.将MySQL数据导入到hdfs 首先我测试将zhaopin表 ...

  9. 一文教你轻松搞定ANR异常捕获与分析方法

    1. ANR 产生原理 关于 ANR 的触发原因,Android 官方开发者文档中 "What Triggers ANR?" 有介绍,如下: Generally, the syst ...

  10. navicat for mysql 破解版

    Navicat for MySQL下载地址:Navicat for MySQL 软件和破解程序 第1步.安装Navicat软件,最后点击完成 第2步.安装成功之后还要进行破解.点击patchNavic ...