【问题标题】:java.lang.ClassCastException in Jetty when using Spring Session with Redis in combination with SseEmitter将 Spring Session 与 Redis 结合使用时,Jetty 中的 java.lang.ClassCastException 与 SseEmitter
【发布时间】:2018-10-31 19:22:26
【问题描述】:

我正在使用 Jetty 9.4(但我也尝试过 9.2)、spring-data-redis 1.8.6 和 Spring 4.2。我基本上使用org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration 提供的默认配置,一切似乎都工作得很好,直到我添加一个Controller,它的端点返回org.springframework.web.servlet.mvc.method.annotation.SseEmitter

@RequestMapping(value = "sse", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<SseEmitter> sse() {
    SseEmitter emitter = new SseEmitter();
    emitter.onCompletion(..);
    emitter.onTimeout(..);

    storeEmitterInHashMap(emitter);

    return ResponseEntity.ok().header("Cache-Control", "no-store").body(emitter);
}

似乎发生的情况是,当 SSE 连接在 30 秒后出现连接超时时,Spring/Jetty 会尝试关闭侦听器。但是由于在控制台中打印了ClassCastException,这失败了:

[WARNING] java.lang.ClassCastException: 
    org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper$HttpSessionWrapper 
    cannot be cast to org.eclipse.jetty.server.session.SessionHandler$SessionIf 
    while invoking onComplete listener
    org.eclipse.jetty.server.session.SessionHandler$SessionAsyncListener@67e50aa3

这大约每 30 秒发生一次。如果我导航到另一个没有连接到 SSE 端点的页面,警告就会消失。

这有什么好担心的吗?这是什么原因造成的?我该如何解决?

【问题讨论】:

    标签: java spring server-sent-events spring-session spring-data-redis


    【解决方案1】:

    这是 Jetty 中的 bug,并在版本 9.4.13.v20181111 中得到修复。

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      • 2016-03-18
      • 2011-05-28
      • 2021-05-10
      • 1970-01-01
      • 2021-04-04
      相关资源
      最近更新 更多