相关疑难解决方法(0)

无法自动装配`WebTestClient` - 无需自动配置

我们使用spring framework 5和spring boot 2.0.0.M6,我们也WebClient用于反应式编程.我们为我们的反应式休息端点创建了测试方法,因此我查找了一些关于如何操作的示例.我发现这个或者这个以及许多其他的都是一样的.他们只是自动装配一个WebTestClient.所以我尝试了同样的事情:

@Log
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class MyControllerTest {

    @Autowired
    private WebTestClient webClient;

    @Test
    public void getItems() throws Exception {
        log.info("Test: '/items/get'");

        Parameters params = new Parameters("#s23lkjslökjh12", "2015-09-20/2015-09-27");

        this.webClient.post().uri("/items/get")
                .accept(MediaType.APPLICATION_STREAM_JSON)
                .contentType(MediaType.APPLICATION_STREAM_JSON)
                .body(BodyInserters.fromPublisher(Mono.just(params), Parameters.class))
                .exchange()
                .expectStatus().isOk()
                .expectHeader().contentType(MediaType.APPLICATION_STREAM_JSON)
                .expectBody(Basket.class);
    }
}
Run Code Online (Sandbox Code Playgroud)

我无法运行,因为我收到错误:

Could not autowire. No beans of 'WebTestClient' type found.
Run Code Online (Sandbox Code Playgroud)

因此,似乎不存在自动配置.我使用的是错误版本还是这里有什么问题?

spring spring-boot spring-webflux

17
推荐指数
2
解决办法
7529
查看次数

标签 统计

spring ×1

spring-boot ×1

spring-webflux ×1