@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>
如上图所示,如果有了,那就可以了。如果还没出现,参考一下这篇文章