java.io.FileNotFoundException: class path resource [mapper/ProductMapper.xml] cannot be opened becau

@Test
public void ioTest() throws IOException {
ClassPathResource classPathResource = new ClassPathResource("mapper/ProductMapper.xml");
InputStream inputStream = classPathResource.getInputStream();
System.out.println(inputStream);
}

上面代码在运行时会报找不到文件的错误,是因为没有mvn install,或者classes没有对应的文件

此时只要在pom.xml中加以下配置,然后重新mvn install,再看target有没有打包相关文件

<build>

<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>

</build>

如上图所示,如果有了,那就可以了。如果还没出现,参考一下这篇文章 

IDEA解决Maven项目编译后classes文件中没有.xml问题_学会放过自己的博客-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值