springboot2.1.1 中集成websocket 單元測試異常
阿新 • • 發佈:2019-01-11
not ble fine creation resource .class clas ebs pat
單元測試在沒有集成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
個類就是程序的入口類。在此做一下記錄
springboot2.1.1 中集成websocket 單元測試異常