1
我嘗試下用java 8的Tomcat 7上運行的WebSocket客戶端,但它拋出異常不起作用
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/inter] threw exception [Handler processing failed; nested exception is java.util.ServiceConfigurationError: javax.websocket.ContainerProvider: Provider org.apache.tomcat.websocket.WsContainerProvider not a subtype] with root cause
java.util.ServiceConfigurationError: javax.websocket.ContainerProvider: Provider org.apache.tomcat.websocket.WsContainerProvider not a subtype
\t at java.util.ServiceLoader.fail(ServiceLoader.java:239)
\t at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
\t at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
\t at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
\t at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
\t at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java:66)
\t at com.shop.inter.service.WebsocketClientEndpoint.<init>(WebsocketClientEndpoint.java:29)
...
它的工作原理上的tomcat 8但在tomcat 7上不起作用。 這是我的websocket類:
@ClientEndpoint
public class WebsocketClientEndpoint {
\t private static final Logger LOGGER = LoggerFactory.getLogger(WebsocketClientEndpoint.class);
\t
\t private Session userSession = null;
\t private MessageHandler messageHandler;
\t public WebsocketClientEndpoint(URI endpointURI) {
\t \t try {
\t \t \t WebSocketContainer container = ContainerProvider.getWebSocketContainer();
\t \t \t container.connectToServer(this, endpointURI);
\t \t } catch (Exception e) {
\t \t \t throw new RuntimeException(e);
\t \t }
\t }
\t /**
\t * Callback hook for Connection open events.
\t *
\t * @param userSession
\t * the userSession which is opened.
\t */
\t @OnOpen
\t public void onOpen(Session userSession) {
\t \t LOGGER.info("opening websocket");
\t \t this.userSession = userSession;
\t }
\t /**
\t * Callback hook for Connection close events.
\t *
\t * @param userSession
\t * the userSession which is getting closed.
\t * @param reason
\t * the reason for connection close
\t */
\t @OnClose
\t public void onClose(Session userSession, CloseReason reason) {
\t \t LOGGER.info("closing websocket");
\t \t this.userSession = null;
\t }
\t /**
\t * Callback hook for Message Events. This method will be invoked when a client send a message.
\t *
\t * @param message
\t * The text message
\t */
\t @OnMessage
\t public void onMessage(String message) {
\t \t if (this.messageHandler != null) {
\t \t \t this.messageHandler.handleMessage(message);
\t \t }
\t }
\t /**
\t * Register message handler
\t */
\t public void addMessageHandler(MessageHandler msgHandler) {
\t \t this.messageHandler = msgHandler;
\t }
\t /**
\t * Send a message.
\t */
\t public void sendMessage(String message) {
\t \t this.userSession.getAsyncRemote().sendText(message);
\t }
\t public void closeUserSession() throws IOException {
\t \t this.userSession.close();
\t }
\t /**
\t * Message handler.
\t *
\t * @author Jiji_Sasidharan
\t */
\t public static interface MessageHandler {
\t \t public void handleMessage(String message);
\t }
}
唯一的依賴是javax.websocket-API 1.1
你能幫我解決這個問題?
它不工作(( – eriksson