由于缺少 ReactiveWebServerFactory bean,无法启动 ReactiveWebApplicationContext [英] Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory bean

查看:227
本文介绍了由于缺少 ReactiveWebServerFactory bean,无法启动 ReactiveWebApplicationContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个新的 springboot 应用程序,我正在尝试开始使用.

I have a new springboot application I am attempting to get started.

我收到的错误是

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 来获取您的依赖项.

I assume you are using maven to get your dependencies.

我使用以下方法解决了这个问题:

I solved the problem by using:

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

这篇关于由于缺少 ReactiveWebServerFactory bean,无法启动 ReactiveWebApplicationContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆