【问题标题】:Spring boot with Stomp gives HttpMessageNotWritableException带有 Stomp 的 Spring Boot 会给出 HttpMessageNotWritableException
【发布时间】:2022-10-13 08:26:28
【问题描述】:

我一直在使用带有 stomp 服务器的 spring boot 和 sockjs 作为前端库的 websocket。我在日志中间歇性地收到以下消息。

11:10:15.017 [37] [http-nio-8080-exec-7] WARN  org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class java.util.LinkedHashMap] with preset Content-Type 'application/javascript;charset=UTF-8']

据我所知,当控制器中收到错误的内容类型时会发生这种情况。但是这些数据是通过 websocket 输入的,所有数据都使用来自前端的JSON.Stringify 进行字符串处理,并由@MessageMapping 注释控制器接收。我无法理解为什么会发生此错误,是否还有其他原因导致此问题发生。我使用 ActiveMQ 作为消息代理。

有人可以对这里可能发生的事情有所了解。

【问题讨论】:

    标签: java spring-boot websocket stomp sockjs


    【解决方案1】:

    我自己弄清楚了这个问题。当 stomp 服务器尝试将心跳从服务器发送到客户端时,会出现问题。如果客户端在服务器发送心跳时断开连接,则会出现此问题。

    【讨论】:

      【解决方案2】:

      感谢您的分享。 我也有类似的例外。 如何消除客户端断开连接时发生的异常?

      Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class java.util.LinkedHashMap] with preset Content-Type 'text/event-stream;charset=UTF-8']
      

      【讨论】:

        猜你喜欢
        • 2016-05-06
        • 2020-06-17
        • 1970-01-01
        • 2023-03-31
        • 1970-01-01
        • 2020-10-31
        • 2016-07-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多