这不是一个错误,这是一个功能…
正如@axtavt和@rhinds所假定的那样,内容类型周围有些混乱。浏览器发送了正确的消息,
Accept:application/json但是spring忽略了这一点,并使用url的扩展名(aarrgh)。从文档:
16.16.4配置内容协商
You can configure how Spring MVC determines the requested media typesfrom the client forrequest mapping as well as for content negotiation purposes. Theavailable options are tocheck the file extension in the request URI, the "Accept" header, arequest parameter, aswell as to fall back on a default content type. By default, fileextension in the requestURI is checked first and the "Accept" header is checked next.
解决方案非常简单,因为您可以禁用此“功能”:
@Configuration@EnableWebMvcpublic class RestCommonsMvcConfig extends WebMvcConfigurerAdapter { @Override public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.favorPathExtension(false); }}


