问题描述
今天在启动项目时,发现网页的图标都加载不出来,打开控制台,发现告警信息是文件解码错误,错误信息:
- Failed to decode downloaded font: http://localhost:8080/plugins/fontawesome-free/webfonts/fa-solid-900.woff2
- OTS parsing error: Failed to convert WOFF 2.0 font to SFNT
- OTS parsing error: incorrect file size in WOFF header
- OTS parsing error: incorrect entrySelector for table directory
如下图:
原因分析
maven打包时:会编译项目文件,如果存在不需要编译的文件需要在配置里面排除。因为有些资源文件被编译后会与原文件不同,导致文件不可用。
问题解决
添加 maven 资源文件管理插件 maven-resources-plugin,指定不过滤的文件扩展名。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- 不过滤字体文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>woff</nonFilteredFileExtension>
<nonFilteredFileExtension>woff2</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
</build>
图标正常加载出来了,控制台也没有告警错误信息。