很多人这样写,
ClassPathResource cpr = new ClassPathResource("xxx.xlsx");
结果怎么也找不到文件,返回 null 。
为什么?
我们要知道,这个类是去找类路径下的资源,
我们去target/classes下看,并没有我们要读取的文件。
而我们的pom文件管理了这些资源文件。
解决办法:
去pom.xml下 节点添加
<resource>
<includes>
<include> template/*.xlsx</include>
</includes>
</resource>