码迷,mamicode.com
首页 > 移动开发 > 详细

java.io.IOException: Could not find resource com/xxx/xxxMapper.xml

时间:2020-12-10 11:20:18      阅读:9      评论:0      收藏:0      [点我收藏+]

标签:lang   tor   r文件   class   ror   could   文件的   rap   code   

java.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

标签:lang   tor   r文件   class   ror   could   文件的   rap   code   

原文地址:https://www.cnblogs.com/Courage129/p/14092255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!