SpringBoot单元测试报java.lang.IllegalStateException: Failed to load ApplicationContext错误的解决方法
大致原因:使用了WebSocket使得在测试环境也得需要启动嵌入式的Servlet容器解决方案:将@SpringBootTest的属性webEnvironment改为SpringBootTest.WebEnvironment.RANDOM_PORT即可@SpringBootTest(webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)以