Java websocket服务器给404

cod*_*der 5 java tomcat websocket

我正在尝试构建一个java websocket服务器.我写了一个简单的服务器端点:

@ServerEndpoint(value = "/test")
public class EndPoint {
    static Queue<Session> queue = new ConcurrentLinkedQueue<Session>();

    public static void send(int a, int b) {
        try {
            for(Session session : queue) {
                session.getBasicRemote().sendText("a = " + a + ",b=" + b);
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }

    @OnOpen
    public void openConnection(Session session) {
        queue.add(session);
    }

    @OnClose
    public void closeConnection(Session session) {
        queue.remove(session);
    }

    @OnError
    public void error(Session session, Throwable t) {
        queue.remove(session);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的web.xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


</web-app>
Run Code Online (Sandbox Code Playgroud)

当我从Javascript点击ws:// localhost:8080/websocket-1.0/test时,我收到了404响应.我正在使用tomcat 8来部署它.我在这里错过了什么?

Sca*_*bat 0

根据此链接https://tyrus.java.net/documentation/1.4/index/websocket-api.html和我的经验,端点应该与 ws: url 匹配

例如

@ServerEndpoint(value = "/test")
ws://localhost:8080/test
Run Code Online (Sandbox Code Playgroud)

或者

@ServerEndpoint(value = "/websocket-1.0//test")
ws://localhost:8080/websocket-1.0/test
Run Code Online (Sandbox Code Playgroud)