【发布时间】:2016-03-13 17:32:28
【问题描述】:
我使用 Spring Boot 来实现一个 REST 应用程序。我有一个像这样映射的资源
@RequestMapping(value = "/{fromLat}/{fromLon}/{toLat}/{toLon:.+}", method = {RequestMethod.GET},
produces = {"application/json"})
因此路径包含坐标,请求看起来像这样
$ curl -I -X GET http://localhost:8085/foobar/53.481297/9.900539/53.491691/9.946046
不幸的是,最后一个结尾被解释为文件扩展名,导致响应头提供文件下载,而不仅仅是纯数据。
Content-Disposition: attachment;filename=f.txt
我认为我可以使用自定义 WebMvcConfigurerAdapter Bean(并且没有 @EnableWebMvc)注释来处理这种情况,就像 here 解释的那样。
public class CustomWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
但这并不能解决问题。不幸的是,检测到的文件扩展名未修复 - 因此我无法使用修复扩展名的规则。
如何将系统配置为仅响应内容而没有 Content-Disposition 标头(导致下载 f.txt)?我不想在末尾使用斜线(“/”)。
我已经看过以下资源
【问题讨论】:
标签: java spring-mvc spring-boot