Caused by: javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same

按照一个博客搞的,然后tomcat起都起不起来,

报错信息是,

java.lang.IllegalStateException: Failed to register @ServerEndpoint class: class com.qcby.config.WebSocket
Caused by: javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/bindingRecord]

然后上网查半天,好像是tomcat已经集成了websocket所以不需要自己再来集成WebSocketConfig,

然后我就把代码中的这一段给注释掉,重启。

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

这次启动倒是不报错了,但是前端的ws请求根本不通啊,然后我又把注释打开了,随便再重启一下,很奇怪又报了一个不一样的错。

Caused by: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to javax.websocket.server.ServerContainer

然后又去查,看到了这篇文章Tomcat 8 和网络套接字,根据他说的,修改依赖,加上scope

      <dependency>
            <groupId>javax.websocket</groupId>
            <artifactId>javax.websocket-api</artifactId>
            <version>1.1</version>
            <scope>provided</scope>
        </dependency>

然后就可以了,有种瞎猫撞上死耗子的感觉,我再去仔细查查为什么要这么改。

posted @ 2023-11-25 15:48  YuKiCheng  阅读(128)  评论(0编辑  收藏  举报  来源