在springboot中通过jdk原生注解@ServerEndpoint开启ws服务,并无收发消息的逻辑
1.添加pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
2.添加配置文件
package com.example.demo.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
@Bean
public WebSocketSpringConfigurator webSocketSpringConfigurator(){
return new WebSocketSpringConfigurator();
}
}
3.配置托管给spring管理
package com.example.demo.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context

最低0.47元/天 解锁文章
785

被折叠的 条评论
为什么被折叠?



