單元測試在沒有集成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
個類就是程序的入口類。在此做一下記錄