一尘不染

Spring Boot-Font Awesome OTS解析错误:转换失败

spring-boot

在Spring Boot / 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

阅读 787

收藏
2020-05-30

共1个答案

一尘不染

问题是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>

此更改允许在打包过程中不过滤字体。

2020-05-30