Spring Boot - Font Awesome OTS parsing error: Fail

2020-05-19 06:42发布

Problem with Fonts not working correctly within a Spring Boot / Spring MVC Application.

The problem is that all of the font files show various errors such as below

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

4条回答
Fickle 薄情
2楼-- · 2020-05-19 07:24

Maybe your file application.properties should be ignored some path like

security.ignored=/css/**,/js/**,/images/**,/font/**
查看更多
三岁会撩人
3楼-- · 2020-05-19 07:40

Encountered the same issue and wasted hours to figure out the issue. This should already been fix in springboot 2.2.4 onwards.

If there are issue, firstly check the downloaded file size in the compiled /target/resources/fonts folder!

Somehow the fonts in this folder are not removed if you copied the first wrong font files. The goal is to make sure the font loaded is to monitor the font size.

Hope this helps for anyone.

查看更多
一纸荒年 Trace。
4楼-- · 2020-05-19 07:41

The issue is that Maven was filtering the font files and corrupting them.

    <resource>
        <directory>${project.basedir}/src/main/resources</directory>
        <filtering>true</filtering>
    </resource>

The fix was to make the following changes to the 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>

This change allows for the fonts to not be filtered during packaging.

查看更多
啃猪蹄的小仙女
5楼-- · 2020-05-19 07:43

Another way to do it is update the configuration of the maven-resources-plugin as follows:

<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>
查看更多
登录 后发表回答