参考:

https://blog.csdn.net/weixin_45953673/article/details/135395986

报错:

Error creating bean with name ‘serverEndpointExporter‘ defined in class path resource

一、代码

WebSocketConfiguration.java

@Configuration

public class WebSocketConfiguration {

    @Bean

    public ServerEndpointExporter serverEndpointExporter() {

        return new ServerEndpointExporter();

    }

}

MyTests.java

@SpringBootTest
public class MyTests {

    @Test

    public void test01() {

        System.out.println("hello");

    }

}

二、问题描述

SpringBoot项目中,test01测试失败,报错如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverEndpointExporter' defined in class path resource [com/lichun/config/WebSocketConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

三、解决方案

修改MyTests.java


@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

public class MyTests {

    @Test

    public void test01() {

        System.out.println("hello");

    }

}