【发布时间】:2021-06-18 18:44:26
【问题描述】:
服务器正在运行,但我无法使用 chatendpoint.java 类。所以 spring 不使用 /user 路径。而且我无法连接 ws://localhost:8080/user 。当我尝试它时,我得到了错误
@ServerEndpoint(value = "/user")
public class ChatEndpoint {
private Session session;
private static final Set<ChatEndpoint> chatEndpoints = new CopyOnWriteArraySet<>();
private static HashMap<String, String> users = new HashMap<>();
@OnOpen
public void OnOpen (Session session) {
System.out.println(" asdasd");
System.out.println(session.toString()+" asdasd");
}
@OnMessage
public void onMessage(Session session, Message message) throws
IOException, EncodeException {
System.out.println("send message");
}
}
@Configuration
@EnableWebSocket
public class WebSocketConfig {
@Bean
public ServerEndpointExporter endpointExporter(){
return new ServerEndpointExporter();
}
}
@SpringBootApplication
public class WebsocketdemoApplication {
public static void main(String[] args) {
SpringApplication.run(WebsocketdemoApplication.class, args);
}
}
我正在使用 spring-boot-starter-websocket 2.3.7.RELEASE 和 spring-websocket 5.2.12.RELEASE
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>2.3.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-messaging -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>5.2.12.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-websocket -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<version>5.2.12.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.7.RELEASE</version>
</dependency>
【问题讨论】:
-
有人可以帮忙吗?
标签: spring-boot java-websocket