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:
- [Solved] Springboot test class injection bean is null Error: java.lang.NullPointerException…
- Solve the error of springboot failed to load ApplicationContext
- When spring boottest performs unit testing, the injection object reports an error and cannot be tested
- How to Solve JAVA Test Class Error: java.lang.nullpointerexception
- WebSocket Error: Unable to unwrap data, invalid status [CLOSED]
- [Solved] Cannot resolve symbol ‘SpringJUnit4ClassRunner’
- No protocol handler valid for the URL
- Spring @Async interrupt/Unable to acquire JDBC Connection
- Spring Boot Error: java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration [How to Solve]
- Springboot: solve the problem of failed to load ApplicationContext