我們試圖將我們的項目之一從Spring 4.0.7.RELEASE遷移到4.1.1.RELEASE。 之後,我們得到以下錯誤。Spring 4.1.1 WebSocket Stomp子協議錯誤
java.lang.IllegalStateException: Multiple protocol handlers configured and no protocol was negotiated. Consider configuring a default SubProtocolHandler.
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.findProtocolHandler(SubProtocolWebSocketHandler.java:294)
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.clearSession(SubProtocolWebSocketHandler.java:433)
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.afterConnectionClosed(SubProtocolWebSocketHandler.java:423)
at org.springframework.web.socket.handler.WebSocketHandlerDecorator.afterConnectionClosed(WebSocketHandlerDecorator.java:85)
at org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.afterConnectionClosed(LoggingWebSocketHandlerDecorator.java:71)
at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.afterConnectionClosed(ExceptionWebSocketHandlerDecorator.java:91)
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.close(AbstractSockJsSession.java:291)
at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.tryCloseWithError(ExceptionWebSocketHandlerDecorator.java:60)
at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.afterConnectionEstablished(ExceptionWebSocketHandlerDecorator.java:50)
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.delegateConnectionEstablished(AbstractSockJsSession.java:207)
at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.initializeDelegateSession(WebSocketServerSockJsSession.java:159)
at org.springframework.web.socket.sockjs.transport.handler.SockJsWebSocketHandler.afterConnectionEstablished(SockJsWebSocketHandler.java:87)
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.onOpen(StandardWebSocketHandlerAdapter.java:101)
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.init(WsHttpUpgradeHandler.java:129)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:633)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1721)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1679)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我們沒有的配置改變任何東西(而不能發現,我們必須改變任何暗示)。
這是我們的WebSockets的服務器端配置。 (它實際上和Spring文檔中的一樣)。
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(final StompEndpointRegistry registry) {
registry.addEndpoint("/tyresearch").withSockJS();
registry.addEndpoint("/tyresearch/changeConfiguration").withSockJS();
registry.addEndpoint("/tyresearch/detailView").withSockJS();
}
@Override
public void configureMessageBroker(final MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
}
而且我們對每個類似下面的方法之前描述的端點:從JavaScript
@MessageMapping("/tyresearch")
public void startTyreSearch(@Payload final TyreSearchRequestContainerDto message, final Principal user, final StompHeaderAccessor) {
....
}
客戶端調用看起來像下面這樣:
var socket = new $wnd.SockJS('/server/api/rest/tyresearch');
var stompClient = $wnd.Stomp.over(socket);
stompClient.connect({}, function(frame) {
console.log('Connected: ' + frame);
});
是否有人有一個想法,有什麼變化讓我們陷入困境,以及如何解決這個問題?
非常感謝。
你好,謝謝你的回答。我試着設置defaultSubProtocols和這些東西,但運行在不同的其他錯誤然後(例如,如果我明確地將stomp協議設置爲SubProtocolWebSocketHandler bean的默認值,我得到一個錯誤告訴我,協議腳本1.0,1.1和1.2是已經映射) 也許我在這裏做了錯誤,所以如果你有一個配置示例,我可以做到這一點,我會試試看。 – Koizumi 2014-11-03 12:08:25
在答案中增加了一個解決方法 – 2014-11-03 12:33:18
該問題已經修復爲4.1.2 - 將於本週發佈。 – 2014-11-03 13:58:08