【问题标题】:Serving static content with custom Content-Type in Spring 5在 Spring 5 中使用自定义 Content-Type 提供静态内容
【发布时间】:2018-07-09 20:04:23
【问题描述】:

我正在尝试将我的应用设置为提供 JSON 架构文件。那部分很容易,并且完成了。我正在努力解决的问题是让它们使用正确的内容类型 - application/schema+json - 而不是默认值 - application/json

我的配置真的很简单:

override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
    registry.addResourceHandler("/api/schemas/**")
            .addResourceLocations("classpath:/schemas/")
}

但是我看不到任何明显的改变任何标题除了缓存的标题。

【问题讨论】:

    标签: spring spring-mvc spring-boot


    【解决方案1】:

    尝试覆盖 configureContentNegotiation 方法。这是我的 Java 代码。贝娄,我为 javascript 模块设置了 "text/javascript" MIME 类型。

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.mediaType("mjs", new MediaType("text","javascript"));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-14
      • 1970-01-01
      • 2019-10-20
      • 2017-10-24
      • 2018-05-23
      • 2019-08-05
      • 1970-01-01
      • 2011-03-13
      相关资源
      最近更新 更多