【发布时间】:2018-05-30 10:24:44
【问题描述】:
当我最终运行项目时,我得到了正确的错误响应。
{
"timestamp": "2018-05-30T10:16:00.065+0000",
"status": 500,
"error": "Internal Server Error",
"message": "No login found for username :string",
"path": "/gatepass/api/v1/logins/login"
}
但是当我在服务器上部署时它会自动转换为 HTML。如何解决这个问题?
<!doctype html>
<html lang="en">
<head>
<title>HTTP Status 500 – Internal Server Error</title>
<style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style>
</head>
<body>
<h1>HTTP Status 500 – Internal Server Error</h1>
<hr class="line" />
<p><b>Type</b> Status Report</p>
<p><b>Message</b> No login found for username :string</p>
<p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p>
<hr class="line" />
<h3>Apache Tomcat/8.5.27</h3>
</body>
</html>
【问题讨论】:
-
这是相同的响应。不同之处在于 Web 容器将响应写入浏览器并因此显示 HTML 标记。您可以将 RequestMapping 中的“produces”选项设置为“application/json”
-
我已经做到了。但我仍然得到 html 格式的响应
-
您能分享您发送响应的代码吗?还有其他相关代码sn-ps?