18

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
3
  • did you resolve this issue? Commented Apr 24, 2021 at 9:41
  • My answer resolved it for me.
    – code
    Commented Apr 29, 2021 at 6:45
  • ok that's great. I tried all option nothing help. then what I did to build again angular project, then everything is fine. perhaps fonts and woff files got corrupt Commented Apr 29, 2021 at 12:26

4 Answers 4

36

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.

2
  • I'm still have the same issue even after added this in my pom.xml. Anyone can help ? Commented Mar 30, 2021 at 3:20
  • I would suggest asking a new question and including your pom.xml
    – code
    Commented Mar 30, 2021 at 6:17
34

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>
5
  • 11
    I personally find this solution cleaner than the accepted solution Commented Mar 26, 2018 at 8:52
  • 2
    A very cleaner solution. should be accepted as an answer due to many valid reasons. Commented Dec 22, 2018 at 20:45
  • 2
    This is the solution that should be used with the POM defaults of Spring Boot starter projects.
    – Encryption
    Commented Apr 12, 2019 at 15:43
  • Thank you. this is perfect, now it feels alot less hackish and i dont have to add all my freaking font directories :) you sir are my hero thank you!
    – Jp Silver
    Commented Nov 8, 2020 at 18:07
  • I'm still have the same issue even after added this in my pom.xml. Anyone can help ? Commented Mar 30, 2021 at 3:20
0

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

security.ignored=/css/**,/js/**,/images/**,/font/**
1
  • 1
    Not sure those settings would affect Maven. Maven was the one introducing the issue.
    – code
    Commented Dec 15, 2015 at 6:17
0

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.

1
  • This comment does'nt help anyone, since the problem is depending on Maven scanning resources and altering them this way. Spring Boot itself is not responsible for that and I don't know how Spring Boot could tell Maven how to behave. With today's Spring Boot v3.1.x you still have to fix it manually. Best answer see postalservice14 above.
    – Slevin
    Commented Jul 15, 2023 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.