我正在尝试在我的 spring 应用程序和 tomcat 中模拟 http 503 状态。所以我创建了一个 Controller :
@RequestMapping(value = "/503", method = RequestMethod.GET)
public String error(final HttpServletRequest request, final HttpServletResponse response, final ModelMap model)
{
response.setStatus(503);
return null;
}
我在 web xml 中设置了过滤器:
<error-page>
<error-code>503</error-code>
<location>/WEB-INF/views/errorpages/simple503.jsp</location>
</error-page>
当我调用/503 Controller 时,显示的是典型的 503 tomcat 页面(不是我想显示的页面),它被称为我的 404 Controller 。
我想这是由 503 Controller 中的 return null 引起的...那么我该怎么做才能返回我的错误页面?
谢谢
最佳答案
您可以(假设您的 View 处理程序识别该字符串):
return "errorpages/simple503";
并使用 @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE)
注释您的 Controller 方法
关于spring - 用tomcat和spring模拟http 503状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11014238/