programing

Reactive Web Server Factory 빈이 없어 Reactive Web Application Context를 시작할 수 없습니다.

cafebook 2023. 4. 3. 21:44
반응형

Reactive Web Server Factory 빈이 없어 Reactive Web Application Context를 시작할 수 없습니다.

시작하려는 새 스프링 부트 애플리케이션이 있습니다.

수신되는 에러는,

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/bubleshadow/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();
  }
}

설정이 무효 테스트에 불충분합니다.

리액티브WebTestClient게다가ReactiveWebApplicationContext응용 프로그램 컨텍스트에 사후 대응 서버가 필요합니다.주석 추가@EnableAutoConfiguration고객님께RootControllerTest스프링이 대신하게 해 줄 거야

자동 구성은 클래스 경로를 검색하여 사후 대응 클래스와 사후 대응 컨텍스트를 찾은 후ReactiveWebServerFactory콩.

당신은 의존관계를 얻기 위해 메이븐을 이용하는 것 같군요.

다음을 사용하여 문제를 해결했습니다.

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

나에게 있어서, 그 오류는 그 실종으로 인해 발생했다.@SpringBootApplication다음을 포함하는 Spring 클래스에 대한 주석main()Boot 어플리케이션을 실제로 기동하는 메서드 진입점.다음을 사용하여 오류를 해결합니다.

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

다운로드가 파손되었을 가능성이 있습니다.~/.m2/저장소를 삭제해 보십시오.

사실 넌 그냥 바뀌기만 하면 돼webEnvironment = WebEnvironment.RANDOM_PORT로.webEnvironment = WebEnvironment.MOCK당신의 안에서@SpringBootTest주석입니다.

@vdou의 답변이 문제 해결에 도움이 되었습니다.

@Enable 추가 외에AutoConfiguration, 스프링 어플리케이션 타입도 수동으로 추가해야 했습니다.

spring:
  main:
    web-application-type: reactive

내 의존관계에는 분명히 스프링이 그 유형을 발견하지 못하게 하는 무언가가 있다.

이게 도움이 됐으면 좋겠는데...

Kotlin을 사용하는 경우 기본 메서드가 포함된 응용 프로그램 클래스에 다음 항목이 없는지 확인합니다.

runApplication<Application>{
    webApplicationType = WebApplicationType.REACTIVE
}

그러면 'RENACTIVE'를 'SERVELET'으로 바꾸면 정말 잘 될 거예요.

위의 솔루션 중 어느 것도 작동하지 않는 경우 추가해 보십시오.

@ContextConfiguration(loader = AnnotationConfigContextLoader.class)

도움이 될 거야

import org.springframework.test.context.support.AnnotationConfigContextLoader;

이 문제가 발생할 수 있는 또 다른 이유는 다음과 같이 표시되지 않은 테스트의 구성 클래스로 Import하는 경우입니다.@TestConfiguration주석

언급URL : https://stackoverflow.com/questions/50329817/unable-to-start-reactivewebapplicationcontext-due-to-missing-reactivewebserverfa

반응형