java.io.IOException: Could not find resource com/xxx/xxxMapper.xml
智慧并不产生于学历,而是来自对于知识的终生不懈的追求。这篇文章主要讲述java.io.IOException: Could not find resource com/xxx/xxxMapper.xml相关的知识,希望能为你提供帮助。
文章图片
java.io.IOException: Could not find resource com/xxx/xxxMapper.xml 报错内容: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSessjava.io.IOException: Could not find resource com/xxx/xxxMapper.xml 报错内容:
org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com/courage/mybatis/mapper/PersonMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/courage/mybatis/mapper/PersonMapper.xml at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:36)
......
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource
报错页面:
文章图片
报错原因:IDEA是不会编译src的java目录的xml文件,所以在Mybatis的配置文件中找不到xml文件!需要人工配置
解决方案一:将xxxMapper.xml放到Maven构建的resource目录下面。
解决方案二:在Maven的pom文件的结尾,添加下面代码,意思是编译配置文件包括src/main/java目录:
<
build>
<
resources>
<
resource>
<
directory>
src/main/java<
/directory>
<
includes>
<
include>
**/*.xml<
/include>
<
/includes>
<
/resource>
<
/resources>
<
/build>
总之,就是要让idea编译到mapper文件!
成功:【java.io.IOException: Could not find resource com/xxx/xxxMapper.xml】
文章图片
推荐阅读
- Android开发——线程池
- android studio 导入外部库文件,以及将项目中module变成library引用依赖
- appium 介绍及环境搭建
- 把bitmap转成文件存入APP项目目录
- uniapp——头部导航栏右侧图标+文字配置
- android studio 点击布局文件隐藏弹出的键盘。
- Mybatis中Mapper.xml文件中注释存在中文报错问题
- SpringBoot2.x 给Controller的RequestMapping添加统一前缀
- 在Intune中同步Apple VPP令牌