springboot打包二次壓縮Excel導致損壞
開發時,將
Excel
文件放到resources
下,通過類加載器流讀取,返回api用于下載該Excel文件。我發現這樣下載的Excel
被損壞了,無法打開,推測是springboo
t打包插件默認對resources
下的所有文件進行了壓縮。Excel
本身是一個壓縮的文件,二次壓縮導致損壞無法打開。
解決方案:
在pom.xml
的build
中添加下面的排除過濾,PS: 我的Excel在 resources/download/xx.xlsx
<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>