WebSocket握手:意外的响应代码:404 - [英] WebSocket handshake: Unexpected response code: 404 -

查看:12052
本文介绍了WebSocket握手:意外的响应代码:404 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习websockets并遵循这里的说明: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html

I am learning about websockets and followed the instructions here: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html

我正在使用tomcat v8 .0.21部署我的webapp但得到以下错误

I' using tomcat v8.0.21 to deploy my webapp but get the following error

当我访问webapp时,我的JavaScript项目看起来很好:我的localhost并访问WebSocketJavaScriptProject

My JavaScript Project looks fine, when I visit the webapp: my localhost and visit WebSocketJavaScriptProject

虽然在控制台窗口中出现错误:WebSocket连接到'ws:// localhost:8080 / WebsocketHome / actions'失败:WebSocket握手期间出错:意外响应代码:404

Although in the console window get the error: WebSocket connection to 'ws://localhost:8080/WebsocketHome/actions' failed: Error during WebSocket handshake: Unexpected response code: 404

我的代码位于此处: https://github.com/darkcloudi/WebSocketProject

我的应用程序和Oracle上的示例之间的差异是我将它拆分为两个项目一个服务和另一个webapp。

Difference between my app and the example on Oracle is I have split it as two projects one service and the other webapp.

我无法弄清楚为什么我会获得404作为服务.war文件称为WebsocketHome。什么会导致这个问题?通常没有找到404,所以猜测它无法找到服务,我确定我做的事情很愚蠢,但无法弄清问题在哪里

I cannot figure out why I would be getting a 404 as the service .war file is called WebsocketHome. Any ideas what would be causing this issue? Usually a 404 is not found so guessing it cannot finding the service , i'm sure i'm doing something stupid but cannot figure out where the problem is

谢谢

推荐答案

握手期间发生错误,因为Tomcat有自己的websi api。因此,您可能在pom.xml中添加了JSR实现或类似javax.websocket-api的内容,在运行时会出现冲突。

The Error during the handshake happens, because Tomcat has its own api for websockets. Thus you might have added the JSR implementation or something similar as javax.websocket-api in your pom.xml there comes a conflict at runtime.

尝试不导出Websocket -library到您的网络服务器,因此它使用自己的实现。

Try to not export your Websocket-library to your webserver, thus it uses its own implementation.

如果您使用maven,请按照提供的方式设置websocket依赖项:

If you use maven, set the websocket dependency as provided:

<!-- Provided Websocket API, because tomcat has its own implementation -->
<dependency>
    <groupId>javax.websocket</groupId>
    <artifactId>javax.websocket-api</artifactId>
    <version>1.1</version>
    <scope>provided</scope>
</dependency>

这篇关于WebSocket握手:意外的响应代码:404 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆