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個類就是程序的入口類。在此做一下記錄


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM