Spring Error Response 自动从 JSON 转换为 Html [英] Spring Error Response auto converted to Html from JSON
本文介绍了Spring Error Response 自动从 JSON 转换为 Html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我最终运行项目时,我得到了正确的错误响应.
I am getting error response correctly when I am running the project in my end.
{
"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.如何解决这个问题?
But when I deploy on server It automatically converts to HTML. How to fix this?
<!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>
推荐答案
这是通过创建一个默认的错误页面来修复的,这样 tomcat 就不会指向错误的 HTML 页面
This is fixed by creating a default error page such that the tomcat does not direct to error HTML page
这篇关于Spring Error Response 自动从 JSON 转换为 Html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文