Web Socket 客户端在 Tomcat 中不起作用 [英] Web Socket Client not working in Tomcat
问题描述
我正在尝试在 Tomcat 的上下文中运行 Web 套接字客户端.所以场景是,我在 Tomcat 上部署了一个 Websocket 服务器端点,作为 App-1 的一部分.同样部署在Tomcat上的App-2(显然在不同的上下文根下),想要发送消息.
I am trying to run a Web socket client under the context of Tomcat. So the scenario is, I have a Websocket Server Endpoint deployed on Tomcat, as part of App-1. App-2, which is also deployed on Tomcat (obviously under different context root), want to send a message.
App-2 中的类工作正常,如果我从主方法中独立运行它.但是当它在 tomcat 的上下文中运行时,它给出了以下错误.(我使用 Tyrus 1.9 作为 JSR-356 impl)
The class in App-2 works fine, if I run it as a stand alone from a main method. But it gives the below error, when it runs under context of tomcat. (I am using Tyrus 1.9 as JSR-356 impl)
java.util.ServiceConfigurationError: javax.websocket.ContainerProvider: Provider org.apache.tomcat.websocket.WsContainerProvider not a subtype
at java.util.ServiceLoader.fail(ServiceLoader.java:239)
at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java:66)
在这一行抛出上述异常:WebSocketContainer container = ContainerProvider.getWebSocketContainer();
The above exception is thrown at this line:
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
有关如何解决此问题的任何建议都会非常有帮助.
Any suggestion on how to fix this will be very helpful.
推荐答案
明白了.问题是,我包括了 tyrus 独立客户端来导入客户端包.我替换了下面的
Got it. The issue was, I was including tyrus stand alone client for importing client packages. I replaced the below
<dependency>
<groupId>org.glassfish.tyrus.bundles</groupId>
<artifactId>tyrus-standalone-client</artifactId>
<version>1.9</version>
</dependency>
有了这个
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
它解决了这个问题.
这篇关于Web Socket 客户端在 Tomcat 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!