1.项目背景:Springboot+SpringMVC+Spring+Mybatis,上传文件
2.问题:上传文件时,报错406,HttpMediaTypeNotAcceptableException Could not find acceptable representation
3.js代码片段:
4.请求头:
5.后台代码片段:
6.解决方案:
Application添加如下红框内的配置
7.原因猜测:
通过config.favorPathExtension(false)
,路径扩展被禁用,不用于确定请求的媒体类型。关于类的更多信息ContentNegotiationConfigurer
,可以看这里https://docs.spring.io/spring/docs/4.1.4.RELEASE/javadoc-api/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.html。