【问题标题】:Spring Boot - Font Awesome OTS parsing error: Failed to convertSpring Boot - Font Awesome OTS 解析错误:转换失败
【发布时间】:2016-03-06 08:36:08
【问题描述】:

字体在 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

【问题讨论】:

  • 您解决了这个问题吗?
  • 我的回答为我解决了这个问题。
  • 好的,太好了。我尝试了所有选项都没有帮助。然后我做了什么来再次构建角度项目,那么一切都很好。也许字体和 woff 文件损坏了

标签: spring-mvc spring-boot font-awesome


【解决方案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>

此更改允许在打包期间不过滤字体。

【讨论】:

  • 即使在我的 pom.xml 中添加了这个,我仍然遇到同样的问题。有人可以帮忙吗?
  • 我建议提出一个新问题并包括你的 pom.xml
【解决方案2】:

另一种方法是更新 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>

【讨论】:

  • 我个人觉得这个解决方案比公认的解决方案更干净
  • 一个非常干净的解决方案。由于许多正当理由,应该被接受为答案。
  • 这是应该与 Spring Boot 启动项目的 POM 默认值一起使用的解决方案。
  • 谢谢。这是完美的,现在感觉不那么骇人听闻了,我不必添加我所有的字体目录 :) 你先生是我的英雄,谢谢!
  • 即使在我的 pom.xml 中添加了这个,我仍然遇到同样的问题。有人可以帮忙吗?
【解决方案3】:

也许你的文件 application.properties 应该被忽略,比如

security.ignored=/css/**,/js/**,/images/**,/font/**

【讨论】:

  • 不确定这些设置是否会影响 Maven。 Maven 是引入这个问题的人。
【解决方案4】:

遇到了同样的问题并浪费了数小时来解决问题。这应该已经在 springboot 2.2.4 及以后修复。

如果有问题,请先检查编译后的/target/resources/fonts文件夹下的下载文件大小!

如果你复制了第一个错误的字体文件,这个文件夹中的字体不会被删除。目标是确保加载的字体是为了监控字体大小。

希望这对任何人都有帮助。

【讨论】:

    猜你喜欢
    • 2021-10-20
    • 2019-09-16
    • 1970-01-01
    • 2018-12-30
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 2019-06-10
    • 2019-01-01
    相关资源
    最近更新 更多