spring - 用tomcat和spring模拟http 503状态

标签 spring http tomcat

我正在尝试在我的 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/

相关文章:

rest - HTTP 2.0 与 HTTP 1.1 在服务器到服务器通信上的连接池

apache - session 在 apache2 ProxyPass 后面的 tomcat8 上过期

mysql - Groovy 性能

java - 创建名为 'webSecurityConfig' 的 bean 时出错,因为当我尝试将 UserService Bean Autowiring 到 WebSecurityConfig 中时,它不存在

java - 通过 ServletContextListener 中的 SimpMessagingTemplate 向所有客户端发送消息

spring - 多个 Spring @Scheduled 任务同时进行

c# - 在 ASP.Net Web Api 2 中使用 PUT 动词上传文件

angular - 错误 NullInjectorError : No provider for HttpClient:

java - 没有任何配置的tomcat 7部署速度慢

java - Spring Aspect 未在测试环境中运行