java - 由于缺少 ReactiveWebServerFactory bean,无法启动 ReactiveWebApplicationContext
问题描述
我有一个新的 springboot 应用程序,我正在尝试开始。
我收到的错误是
org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory bean.
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:76) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
src/main/java/bubbleshadow/RootController.java
package bubbleshadow;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@RestController
public class RootController {
public RootController() {
}
@GetMapping("/")
public Mono<HttpStatus> returnOk() {
return Mono.just(HttpStatus.OK);
}
}
src/test/java/test/bubbleshadow/RootControllerTest.java
package test.bubbleshadow;
import bubbleshadow.RootController;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes=RootController.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
public class RootControllerTest {
@Autowired
WebTestClient webTestClient;
@Test
public void baseRouteShouldReturnStatusOK() {
webTestClient.head().uri("/").exchange().expectStatus().isOk();
}
}
解决方案
我假设您正在使用 Maven 来获取您的依赖项。
我通过使用解决了这个问题:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
代替:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
推荐阅读
- android - Ionic Cordova 构建 android 在 :processDebugGoogleServices 失败,原因是“没有为包名称 'io.ionic.starter' 找到匹配的客户端”
- java - 获取更新文本视图的 HTTP 请求
- excel - 获取条件格式的单元格(DupeUnique = xlDuplicate)
- list - 如何创建 n 维列表?
- javascript - 将部分视图包装在表单中并从中获取提交数据
- android - 文本到语音的古吉拉特语语言环境
- python - 更改 pandastable 中显示的数据框(tkinter 小部件)
- node.js - 以 sudo 用户身份安装软件包时出现 npm 错误消息
- .net - 在一个表达式中查找多个文本
- tensorflow - F tensorflow/stream_executor/cuda/cuda_dnn.cc:522] 检查失败