使用mybatis框架和maven错误Cause: java.io.IOException: Could not find resource com/qiuyu/dao/UserMapper.xml

本文解决了一个常见的MyBatis问题:在Maven项目中找不到UserMapper.xml文件。通过调整XML文件的位置和修改pom.xml中的资源配置,成功解决了Mapper文件未被加载的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错Cause: java.io.IOException: Could not find resource com/qiuyu/dao/UserMapper.xml

该报错我在网上查看到有好几个方法

该错误原因:是因为maven得过滤问题

解决方法有 (最后说我遇见得问题):

1. .把usermapper.xml放到resources里面得com.qiuyu.dao
2. .把有pom.xml得地方都加上下面代码

<!--在build中配置resources来防止我们导出资源失败-->
    <build>
        <!-- 定义classpath -->
        <resources>
            <!-- resources文件 -->
            <resource>
                <directory>src/main/resources</directory>
                <!-- 是否被过滤,如果被过滤则无法使用 -->
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <!-- java文件夹 -->
            <resource>
                <directory>src/main/java</directory>
                <!-- 引入映射文件等 -->
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
    </build>

如:在这里插入图片描述
我遇到的问题如下:

我的xml文件已经让编译存在了 ,但是他不是应该在得位置
所以我确定不是因为maven过滤得原因。

    <mappers> 这是拿到这个文件得方法
        <mapper resource="com/qiuyu/dao/UserMapper.xml"/>
    </mappers>

我写的就是找不到, 放不到照片中得第一个圈里面
他是在外面得com.qiuyu.dao(第2个圈)里面
在这里插入图片描述
解决办法:很狗·····

    <mappers>
        <mapper resource="com.qiuyu.dao/UserMapper.xml"/>
    </mappers>

这样就可以找到了 欸~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码农哈慈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值