javax.websocket.server.ServerContainer not available

Original address: https://blog.csdn.net/chunjusu2447/article/details/100820520

Websocket is integrated in the springboot project. During unit testing, the following errors occur:

javax.websocket.server.ServerContainer not available

The original annotation of the unit test class is as follows:

     

    @RunWith(SpringRunner.class)

     

    @SpringBootTest

After consulting the data, we know that the server will not be started when springboottest is started, so websocket will naturally report an error. At this time, we need to add the option webenvironment to provide a web environment for testing. As follows:

     

    @RunWith(SpringRunner.class)

     

    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_ PORT)

Similar Posts: