您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

SpringMVC:不一致的映射行为取决于URL扩展名

SpringMVC:不一致的映射行为取决于URL扩展名

这不是一个错误,这是一个功能

正如@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);
    }

}
Java 2022/1/1 18:14:53 有492人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶