springboot2.1.1 中集成websocket 单元测试异常

单元测试在没有集成websocket之前是好好的,当集成websocket之后就出现了下面的异常(只贴出来关键信息):

2019-01-11 10:05:42 [ERROR] [org.springframework.boot.SpringApplication:858] - Application run failed 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverEndpointExporter' defined in class path resource [com
Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

个人猜想异常原因就是因为@ServerEndpoint注解引起的

于是在单元测试上面添加了下面的注解就可以运行了:

@SpringBootTest(classes = {Application.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)

Application个类就是程序的入口类。在此做一下记录

猜你喜欢

转载自www.cnblogs.com/andysd/p/10253747.html