spring boot整合websocket之使用自带tomcat启动项目报错记录

项目中用到websocket,就将原来写好的websocket工具类直接拿来使用,发现前端建立连接的时候报404,经查找发现是因为原来用的是配置的外部tomcat启动,这次是spring boot自带的启动,查找看网上说要加入以下配置:

1,添加依赖

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>

2,添加配置

@Configuration
public class WebSocketConfig {

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

}

3,添加注解@Component

@ServerEndpoint(value = "/socket/{userId}")
@Component
public class SocketServer{}

结果启动报错:

Error creating bean with name 'serverEndpointedExporter' defined in class path resource 

Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

查了半天发现按照网上的方法改了都没有用,后同事提示说看看依赖是否有冲突,经过检查发现确是因为依赖冲突了,解决了冲突之后成功启动,可以和前端建立连接

猜你喜欢

转载自www.cnblogs.com/cailijuan/p/11717935.html
今日推荐