我正在尝试编写一个基于Spring和Netty的简单WebSocket服务器应用程序。
我的应用程序看起来像这样
@SpringBootApplication
public class DemoReactiveWSApp {
public static void main(String[] args) {
SpringApplication.run(DemoReactiveWSApp.class, args);
}
}
使用以下配置
@Configuration
public class WebSocketConfig {
@Bean
public HandlerMapping handlerMapping() {
final Map<String, WebSocketHandler> handlerMap = new HashMap<>();
// will be populated later with routes and handlers
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
mapping.setUrlMap(handlerMap);
mapping.setOrder(-1);
return mapping;
}
@Bean
public RequestUpgradeStrategy requestUpgradeStrategy() {
return new ReactorNettyRequestUpgradeStrategy();
}
}
当我运行它时,一切都会启动,我可以尝试(现在)建立WS连接。
然而,当我想在测试中启动时
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class DemoReactiveWSAppTest {
@LocalServerPort
private String port;
@Test
public void givenContext_WhenStartingApplication_ThenItLoads() throws InterruptedException {
System.out.println("Port: " + port);
}
}
服务器似乎永远不会启动。
我忘记了什么吗?
答案 0 :(得分:0)
愚蠢的我,我忘了@RunWith(SpringRunner.class)