Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory bean

Tags:

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

The error I receive is

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();   } } 
like image 591
Daniel Lynch Avatar asked May 14 '18 12:05

Daniel Lynch


Video Answer


2 Answers

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> 

Instead of:

    <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-webflux</artifactId>         <version>5.0.7.RELEASE</version>     </dependency> 
like image 53
François Dupire Avatar answered Oct 01 '22 04:10

François Dupire


Your configuration is not sufficient for reactive tests.

The reactive WebTestClient as well as ReactiveWebApplicationContext need reactive server in the application context. Add annotation @EnableAutoConfiguration to your RootControllerTest and let Spring's do it for you.

The autoconfiguration searches your class path and after find reactive classes and reactive context then create ReactiveWebServerFactory bean.

like image 45
vdou Avatar answered Oct 01 '22 06:10

vdou