1. 程式人生 > 實用技巧 >Java學習-068-Springboot 解決 maven 資源過濾導致的網頁按鈕圖示顯示異常( Failed to decode downloaded font )

Java學習-068-Springboot 解決 maven 資源過濾導致的網頁按鈕圖示顯示異常( Failed to decode downloaded font )

使用 Springboot + layui 進行網頁開發時,頁面圖示顯示異常,如下圖所示。

遇到此問題後,解決的步驟如下所示:

1、檢視 war 包檔案中的樣式檔案是否存在 --- 樣式檔案中css樣式檔案存在;

2、使用 chrome 開發者模式,發現控制檯輸出Failed to decode downloaded font 錯誤,顯示樣式檔案解碼載入失敗;

3、替換war包中的樣式檔案後,重啟 --- 圖示顯示正常,定位打包過程存在問題,導致了檔案被破壞

4、猴精多方查賬,是 maven 的 filter 未配置過濾資訊,導致打包過程中破壞了 font 檔案的二進位制檔案格式,引發前端頁面解析檔案出錯,致使圖示顯示異常

5、配置 maven 的 filter 資訊(如下所示),重新打包部署後,問題解決

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>static/**/*.woff</exclude
> <exclude>static/**/*.woff2</exclude> <exclude>static/**/*.ttf</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</
filtering> <includes> <include>static/**/*.woff</include> <include>static/**/*.woff2</include> <include>static/**/*.ttf</include> </includes> </resource> </resources> </build>