java - 如何解决 Spring 3.0 MVC 中的“mediaType”不能为空错误?
问题描述
如何解决mediaType
Spring 3.0 MVC 中不能为空的错误?我们希望为移动应用程序实现“支持通用链接”的要求之一:
文件路径应该是:http://localhost:9080/.well-known/apple-app-site-association
当我请求 URL 时,https://localhost:9080/.well-known/apple-app-site-association
我们收到以下错误:
错误:
[5/7/18 10:54:38:776 EDT] 00000125 SystemOut O 2018-05-07 10:54:38,757 ERROR PageController - Exception while processing request for: /.well-known/apple-app-site-association
java.lang.IllegalArgumentException: 'mediaType' must not be empty
at org.springframework.util.Assert.hasLength(Assert.java:136) ~[spring-core-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.http.MediaType.parseMediaType(MediaType.java:687) ~[spring-web-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at com.sdl.webapp.common.impl.interceptor.StaticContentInterceptor.fallbackForContentProvider(StaticContentInterceptor.java:79) ~[dxa-common-impl-1.5.0.jar:1.5.0]
at com.sdl.webapp.common.impl.interceptor.StaticContentInterceptor.preHandle(StaticContentInterceptor.java:111) ~[dxa-common-impl-1.5.0.jar:1.5.0]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:914) ~[spring-webmvc-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) ~[spring-webmvc-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) ~[spring-webmvc-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) ~[spring-webmvc-3.1.4.RELEASE.jar:3.1.4.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:575) [javax.j2ee.servlet.jar:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) [javax.j2ee.servlet.jar:na]
我的控制器:
package com.sdl.webapp.main.controller;
import com.sdl.webapp.common.api.WebRequestContext;
import com.sdl.webapp.common.api.localization.Localization;
import com.sdl.webapp.common.api.localization.LocalizationResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
@Controller
public class AdminController
{
private static final Logger LOG = LoggerFactory.getLogger(AdminController.class);
private String successView;
@Autowired
private WebRequestContext webRequestContext;
@Autowired
private LocalizationResolver localizationResolver;
public AdminController() {}
@RequestMapping(method=RequestMethod.GET, value="/.well-known/apple-app-site-association", headers="content-type=application/json", produces = "application/json", consumes = "application/json")
public String getHeaders(@RequestHeader(value="Content-Type", required=false, defaultValue="application/json") String ContentType, @RequestHeader(value="Accept", defaultValue="application/json") String accept)
{
Localization localization = webRequestContext.getLocalization();
LOG.trace("ContentType : " + ContentType);
return localization.getPath() + "/.well-known/apple-app-site-association";
}
}
解决方案
将产品类型添加到@RequestMapping()
例子 :
produces = MediaType.APPLICATION_JSON_VALUE
produces = MediaType.TEXT_PLAIN_VALUE
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE}
推荐阅读
- python - TypeError: object() 没有参数(trex 恐龙机器人)
- php - laravel 5.6 未从 laravel 中的控制器读取变量
- twitter-bootstrap - 在 vue.js 中改变颜色
- android - 共享图像意图在三星 S8 中不起作用
- node.js - npm 请求或 https 模块哪个更好
- grand-central-dispatch - 在 NSDocumentSubclass 初始化期间显示一个窗口
- css - css倾斜元素并获得内部圆角边框顶部
- javascript - 使用 Openseadragon 在大图像上使用 IE 11/Edge 得到“IndexSizeError”
- python-2.7 - 在 Python 中结束循环时停止 While 循环
- ubuntu - 粉碎(破折号)不在ubuntu上发送事件