我在 AWS EB 中使用 Tomcat。我开发了一个应用程序,使用 Spring boot 技术堆栈 Spring 4 和 Java 8。我的应用程序使用 Spring WebSocket 向用户发送通知。以下是 javascript 条目
<script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.1.4/sockjs.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js" ></script>
// Create and init the SockJS object
var socket = new SockJS('/partnervestcrm/message');
var stompClient = Stomp.over(socket);
// Subscribe the '/notify' channell
stompClient.connect({}, function(frame) {
stompClient.subscribe('/user/queue/notify', function(notification) {
// Call the notify function when receive a notification
//notify(JSON.parse(notification.body).message);
notify(JSON.parse(notification.body));
});
}, function(error) {
alert("STOMP error " + error);
});
当部署到 AWS EB 时,这在我的本地运行良好,但出现以下错误
WebSocket connection to 'ws://xxxxx/notification/298/plu4ia32/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
WrappedWebSocket @ VM152:164
e.exports @ websocket.js:6
r @ websocket.js:32
r._connect @ main.js:219
r._receiveInfo @ main.js:193
n @ emitter.js:30
r.emit @ emitter.js:50
(anonymous) @ info-receiver.js:67
n @ emitter.js:30
r.emit @ emitter.js:50
(anonymous) @ info-ajax.js:37
n @ emitter.js:30
r.emit @ emitter.js:50
xhr.onreadystatechange @ abstract-xhr.js:124
你能告诉我如何解决这个问题吗?
最佳答案
为安全组添加入站规则解决了这个问题。请在 ec2 dashboard > NETWORK & SECURITY(在左 Pane 中)> security groups > inbound 添加规则
关于amazon-web-services - AWS ElasticBeanstalk Tomcat 和 Spring 中的 Websocket 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46640648/