springboot打包二次压缩Excel导致损坏
开发时,将
Excel
文件放到resources
下,通过类加载器流读取,返回api用于下载该Excel文件。我发现这样下载的Excel
被损坏了,无法打开,推测是springboo
t打包插件默认对resources
下的所有文件进行了压缩。Excel
本身是一个压缩的文件,二次压缩导致损坏无法打开。
解决方案:
在pom.xml
的build
中添加下面的排除过滤,PS: 我的Excel在 resources/download/xx.xlsx
xml
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.xlsx</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.xlsx</include>
</includes>
</resource>
</resources>
