正如@axtavt和@rhinds所假定的那样,内容类型周围有些混乱。浏览器发送了正确的消息,Accept: application/json
但是spring忽略了这一点,并使用url的扩展名(aarrgh)。从文档:
16.16.4配置内容协商
You can configure how Spring MVC determines the requested media types
from the client for
request mapping as well as for content negotiation purposes. The
available options are to
check the file extension in the request URI, the "Accept" header, a
request parameter, as
well as to fall back on a default content type. By default, file
extension in the request
URI is checked first and the "Accept" header is checked next.
@Configuration
@EnableWebMvc
public class RestCommonsMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}