浏览器报警告,Failed to decode downloaded font和OTS parsing error: Failed to convert WOFF 2.0 font to SFNT

文章目录

  • 静态资源文件拦截
  • 字体报错 Failed to decode downloaded font

静态资源文件拦截

在整合一个前端框架到我的项目中的时候,浏览器报404,这个很容易解决,Spring拦截器给拦截了,在Spirng中配置一下不拦截规则即可。
浏览器报警告,Failed to decode downloaded font和OTS parsing error: Failed to convert WOFF 2.0 font to SFNT_第1张图片
配置Spring拦截规则

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
	}
	/**
	 * 配置静态资源文件路径
	 * @param registry
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**/*").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/static/");
	}
}

字体报错 Failed to decode downloaded font

浏览器报警告,Failed to decode downloaded font和OTS parsing error: Failed to convert WOFF 2.0 font to SFNT_第2张图片
如何排查都找不到问题的原因。后来在网上看到,maven打包的时候会过滤文件
在maven的filter解析font文件时,它破坏了font文件的二进制文件格式,导致浏览器解析出错。
maven打包不过滤静态文件,每一个resource里面都需要配置include或者exclude,少了都会报错

<build>
	<resources>
            <resource>
                <directory>src/main/resourcesdirectory>
                <filtering>truefiltering>
                <includes>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <excludes>
                    <exclude>static/**exclude>
                excludes>
            resource>
            <resource>
                <directory>src/main/resourcesdirectory>
                <filtering>falsefiltering>
                <includes>
                    <include>static/**include>
                includes>
            resource>
            <resource>
                <directory>src/main/resourcesdirectory>
                <filtering>truefiltering>
                <excludes>
                    <exclude>static/**exclude>
                excludes>
            resource>
        resources>
build>

你可能感兴趣的:(Maven,Front)