Spring Boot - Font Awesome OTS parsing error: Failed to convert
Spring Boot - Font Awesome OTS parsing error: Failed to convert
字体在 Spring 引导/Spring MVC 应用程序中无法正常工作的问题。
问题是所有的字体文件都显示如下各种错误
Failed to decode downloaded font: http://localhost:8080/fonts/fontawesome-webfont.woff2?v=4.4.0
OTS parsing error: Failed to convert WOFF 2.0 font to SFNT
Failed to decode downloaded font: http://localhost:8080/fonts/fontawesome-webfont.woff?v=4.4.0
OTS parsing error: incorrect file size in WOFF header
Failed to decode downloaded font: http://localhost:8080/fonts/fontawesome-webfont.ttf?v=4.4.0
OTS parsing error: incorrect entrySelector for table directory
问题是 Maven 过滤并破坏了字体文件。
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
修复方法是对 pom.xml
进行以下更改
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>static/fonts/**</exclude>
</excludes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>static/fonts/**</include>
</includes>
</resource>
此更改允许在打包期间不过滤字体。
也许您的文件 application.properties
应该被忽略,例如
security.ignored=/css/**,/js/**,/images/**,/font/**
另一种方法是更新 maven-resources-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>
遇到了同样的问题,浪费了几个小时来解决问题。这应该已经在 springboot 2.2.4 之后修复了。
如果有问题,首先检查编译后的/target/resources/fonts文件夹中下载的文件大小!
不知何故,如果您复制了第一个错误的字体文件,此文件夹中的字体不会被删除。目标是确保加载的字体是监控字体大小。
希望这对任何人都有帮助。
字体在 Spring 引导/Spring MVC 应用程序中无法正常工作的问题。
问题是所有的字体文件都显示如下各种错误
Failed to decode downloaded font: http://localhost:8080/fonts/fontawesome-webfont.woff2?v=4.4.0
OTS parsing error: Failed to convert WOFF 2.0 font to SFNT
Failed to decode downloaded font: http://localhost:8080/fonts/fontawesome-webfont.woff?v=4.4.0
OTS parsing error: incorrect file size in WOFF header
Failed to decode downloaded font: http://localhost:8080/fonts/fontawesome-webfont.ttf?v=4.4.0
OTS parsing error: incorrect entrySelector for table directory
问题是 Maven 过滤并破坏了字体文件。
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
修复方法是对 pom.xml
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>static/fonts/**</exclude>
</excludes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>static/fonts/**</include>
</includes>
</resource>
此更改允许在打包期间不过滤字体。
也许您的文件 application.properties
应该被忽略,例如
security.ignored=/css/**,/js/**,/images/**,/font/**
另一种方法是更新 maven-resources-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>
遇到了同样的问题,浪费了几个小时来解决问题。这应该已经在 springboot 2.2.4 之后修复了。
如果有问题,首先检查编译后的/target/resources/fonts文件夹中下载的文件大小!
不知何故,如果您复制了第一个错误的字体文件,此文件夹中的字体不会被删除。目标是确保加载的字体是监控字体大小。
希望这对任何人都有帮助。