Spring 使用 Stomp 启动会出现 HttpMessageNotWritableException

Spring boot with Stomp gives HttpMessageNotWritableException

我一直在使用 spring boot with stomp server for websocket with sockjs 作为前端库。我间歇性地在日志中收到以下消息。

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 作为消息代理。

谁能解释一下这里可能发生的事情。

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