若在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