2 回答
TA贡献1773条经验 获得超3个赞
异常表明问题是什么:
Caused by: java.lang.ClassNotFoundException: javax.websocket.ClientEndpointConfig$Configurator at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 2 more
javax.websocket.ClientEndpointConfig$Configurator
找不到该类。请确保正确的类加载器可以访问所有必要的类来运行您的应用程序。
TA贡献1872条经验 获得超3个赞
问题是在连接时stompClient.connect(socketURL,sessionHandler).get();我还添加了实际发生错误的注释。transports.add(new WebSocketTransport(new JettyWebSocketClient()));我通过替换为解决了这个问题transports.add(new RestTemplateXhrTransport());
以下是变化:
public static StompSession createStompWSConnection(String socketURL,StompSessionHandler sessionHandler) throws Exception {
List<Transport> transports = new ArrayList<Transport>();
//transports.add(new WebSocketTransport(new StandardWebSocketClient()));
//transports.add(new WebSocketTransport(new JettyWebSocketClient()));
transports.add(new RestTemplateXhrTransport());
SockJsClient sockJsClient = new SockJsClient(transports);
WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
//stompClient.setMessageConverter(new Mapp);
StompSession session = stompClient.connect(socketURL,sessionHandler).get(); //error occurs here
System.out.println("Session : " + session);
session.subscribe("/queue/msg", sessionHandler);
return session;
}
添加回答
举报