Spring SseEmitter导致响应提交后无法转发异常 [英] Spring SseEmitter causes Cannot forward after response has been committed exception

查看:59
本文介绍了Spring SseEmitter导致响应提交后无法转发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个具有如下方法的简单控制器:

Given a simple controller with a method like this:

@RequestMapping(method = RequestMethod.GET, value = "{id}/update")
public ResponseEntity<SseEmitter>  update() throws IOException {
    final SseEmitter  sseEmitter = new SseEmitter();

    return ResponseEntity.ok(sseEmitter);
}

我也这样试过:

@RequestMapping(method = RequestMethod.GET, value = "{id}/update")
public SseEmitter  update() throws IOException {
    final SseEmitter  sseEmitter = new SseEmitter();

    return sseEmitter;
}

但是,Tomcat 8.0.21 在发出请求 30 秒后,两种方式都会抛出上述异常.幕后发生了什么?

But both way Tomcat 8.0.21 throws the aforementioned exception 30 seconds after the request issued. What is happening under the hood?

推荐答案

这可能是 servlet 容器的默认异步超时.您可以使用 Spring 更改默认值:

This may be the default async timeout of your servlet container. You can change the default value with Spring:

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
        configurer.setDefaultTimeout(1000000);
    }

}

这篇关于Spring SseEmitter导致响应提交后无法转发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆