Mybatis报错:Could not find resource mybatis-conf.xml
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的更多相关文章
- 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 ...
- mybatis报错:Invalid bound statement (not found)
mybatis报错:Invalid bound statement (not found)的原因很多,但是正如报错提示一样,找不到xml中的sql语句,报错的情况分为三种: 第一种:语法错误 Java ...
- Springboot项目下mybatis报错:Invalid bound statement (not found)
mybatis报错:Invalid bound statement (not found)的原因很多,但是正如报错提示一样,找不到xml中的sql语句,报错的情况分为三种: 第一种:语法错误 Java ...
- Mybatis 报错
Mybatis 报错 builder.BuilderException: Error parsing SQL Mapper Configuration Caused by: org.apache.ib ...
- 解决Mybatis 报错Invalid bound statement (not found)
解决Mybatis 报错Invalid bound statement (not found) 出现此错误的原因 1.xml文件不存在 2.xml文件和mapper没有映射上 namespace指定映 ...
- 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 ...
- SpringBoot使用MyBatis报错:Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL)
© 版权声明:本文为博主原创文章,转载请注明出处 1. 错误描述 使用SpringBoot集成MyBatis框架,并且使用 mapper-spring-boot-starter 自动生成MyBati ...
- oracle+mybatis报错:BindingException("Invalid bound statement (not found): ")
oracle+mybatis报错:BindingException("Invalid bound statement (not found): ") 从mysql转到oracle数 ...
- 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 ...
随机推荐
- CSS鼠标指针cursor样式
参考来源:W3SCHOOL 有时我们需要在CSS布局时设定特定的鼠标指针样式,这时可以通过设定cursor来实现: url: 需使用的自定义光标的 URL. 注释:请在此列表的末端始终定义一种普通的光 ...
- python多元回归于调用excel文件
import xlrd from numpy.linalg import inv import numpy as np data = xlrd.open_workbook(u'C:\\Users\\x ...
- C#获取时间戳的几种方式
Console.WriteLine(Convert.ToDouble(DateTime.UtcNow.Ticks - 621355968000000000) / (10 * 1000 * 1000)) ...
- python初学者-鸡兔同笼简单算法
鸡兔同笼问题.假设共有鸡.兔30只,脚90只.求鸡.兔各有多少只 使用for循环快速解决鸡兔同笼问题 for ji in range(0,31): if 2*ji+(30-ji)*4==90: pri ...
- 【探索之路】机器人篇(1)-ROS-mwRobot开篇
机器人的定义 首先,什么才是机器人?机器人是不是必须和人一样的外形?我们先看一看维基百科给机器人的定义: 由上可见,机器人并不是和人一样的外形,而是可以模拟人类行为或者思想再或者是模拟其他生物的机械. ...
- Ubuntu+KVM显卡透传
好久没有更新微博了,最近有点忙,大家见谅啊!今天带来的是我前段时间做的东西,也就是在 Ubuntu下做KVM虚拟机显科透传.(最近人有点懒,其实有几次是有时间更新的,但是就是懒得动,唉!得保持清醒不能 ...
- Class 类文件结构
本文部分摘自<深入理解 Java 虚拟机第三版> 概述 我们知道,Java 具有跨平台性,其实现基础就是虚拟机和字节码存储格式.Java 虚拟机不与 Java 语言绑定,只与 Class ...
- window10 安装Mysql 8.0.17以及忘记密码重置密码
一.安装Mysql8.0.17 1:首先去官网下载安装包 下载地址:https://dev.mysql.com/downloads/mysql/ 2:将解压文件解压到你安装的目录:D:\mysql\m ...
- Head First 设计模式 - 01. 策略 (Strategy) 模式
当涉及到"维护"时,为了"复用"目的而使用继承,结局并不完美 P4 对父类代码进行修改时,影响层面可能会很大 思考题 利用继承来提供 Duck 的行为,这会导致 ...
- 机器学习之shape
shape[:2] 取彩色图片的长和宽 shape[:3]取彩色图片的长和宽和通道 img.shape[0]:图像的垂直高度 img.shape[1]:图像的水平宽度 img.shape[2]:图像的 ...