使用WebSocket导致jUnit单元测试报No suitable default RequestUpgradeStrategy found错误的解决方法

若在SpringMVC项目中使用了WebSocket,在运行jUnit单元测试时,可能会报如下错误:

Caused by: java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found

若出现上述异常,在Maven的pom.xml中添加如下依赖,问题即可解决:

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>7.0.52</version>
<scope>test</scope>
</dependency>

Reference:
StackOverflow

发表评论

电子邮件地址不会被公开。 必填项已用*标注