spring - 无法在 Angular 5 中解码下载的字体
问题描述
编辑:我可以相对清楚地说,这是我的 Spring 应用程序的一个问题。将其上传到我的测试火力库中,不会触发这样的警告。
亲爱的程序员...
相信我,当我说,我真的尝试过在其他人的问题中发布的许多其他解释。这只是一个非常奇怪的案例。
我想尝试在 Spring 后端部署我的 Angular 5 应用程序。这真的是一个看起来像这样的准系统设置......
@SpringBootApplication
public class AngularApplication extends SpringBootServletInitializer {
@Configuration
@EnableConfigurationProperties({ ResourceProperties.class })
public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
private ResourceProperties resourceProperties = new ResourceProperties();
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
long cachePeriod = resourceProperties.getCache().getPeriod().getSeconds();
final String[] staticLocations = resourceProperties.getStaticLocations();
final String[] indexLocations = new String[staticLocations.length];
registry.addResourceHandler(
"/**/*.css",
"/**/*.js")
.addResourceLocations(staticLocations)
.setCacheControl(CacheControl.maxAge(cachePeriod, TimeUnit.SECONDS));
registry.addResourceHandler(
"/**/*.html",
"/**/*.json",
"/**/*.bmp",
"/**/*.jpeg",
"/**/*.jpg",
"/**/*.png",
"/**/*.ttf",
"/**/*.svg",
"/**/*.eot",
"/**/*.woff",
"/**/*.woff2"
)
.addResourceLocations(staticLocations)
.setCacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS));
registry.addResourceHandler("/**").addResourceLocations(indexLocations).resourceChain(true)
.addResolver(new PathResourceResolver() {
@Override
protected Resource getResource(String resourcePath, Resource location) {
return location.exists() && location.isReadable() ? location : null;
}
});
}
}
public static void main(String[] args) {
SpringApplication.run(AngularApplication.class, args);
}
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(BizviewAngularApplication.class);
}
}
我对我的应用程序进行了富有成效的构建,将它放在我的 Spring 应用程序的静态文件夹中并运行它。外观和感觉都很棒,总而言之。没有错误,我几乎可以在每个浏览器上看到我的页面。Edge,Opera,Firefox,但仅在 Chrome 浏览器中,我会弹出一个警告,当窗口重绘时会成倍增加...
Failed to decode downloaded font
和OTS parsing error: invalid version tag
。我删除了 font-awesome 并重新安装了 4.7,但这并没有帮助。奇怪的是,字体很棒的图标都很好。我可以看到它们,并且项目中没有任何遗漏。我的意思是,这是我推出的第一个应用程序,所以我可能会遗漏一些东西,但这似乎是一个奇怪的具体问题
解决方案
我在使用重写规则托管 IIS 8.5 时遇到了这个问题。据我了解,问题在于文件扩展名实际上被解释为.woff?v=4.7.0
.
所以我最终将它添加到我的字体扩展列表中。我对 Spring 一无所知,但是从您的列表中,我认为您应该将其添加到registry.addResourceHandler
:
registry.addResourceHandler(
"/**/*.html",
"/**/*.json",
"/**/*.bmp",
"/**/*.jpeg",
"/**/*.jpg",
"/**/*.png",
"/**/*.ttf",
"/**/*.svg",
"/**/*.eot",
"/**/*.woff",
"/**/*.woff?v=4.7.0",
"/**/*.woff2"
)
推荐阅读
- laravel - laravel 分析中“Period::days(1)”的时间段是多少?
- python - Ctx 是缺少 discrd.py 的必需参数
- python - 使用线程继承限制线程数
- php - 模型检索数据丢失的蛋糕 PHP 2.10 内部连接?
- swift - 当键盘隐藏在swift中时增加inputAccessoryView的高度
- angular - 如何在图表js中对齐网格线上的条形图
- reactjs - React 测试库模拟 rxjs webSocket
- javascript - 有没有办法改变 context.scale 的缩放方式?
- curl - 当我执行 curl 命令时收到“消息”:“禁止,错误:代码 = 403,消息 = 禁止”
- java - 在 Wildfly 中重新部署战争时出现 ClassCastingException