【发布时间】:2018-06-21 22:32:08
【问题描述】:
我们正在使用 spring 框架 5 和 spring boot 2.0.0.M6,我们还使用 WebClient 进行响应式编程。我们为我们的反应式休息端点创建了测试方法,因此我查找了一些有关如何执行此操作的示例。我发现this 一个或this 和许多其他的都一样。他们只是自动连接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);
}
}
我无法运行它,因为我收到了错误:
Could not autowire. No beans of 'WebTestClient' type found.
所以似乎不存在自动配置。是我用错了版本还是怎么回事?
【问题讨论】:
标签: spring spring-boot spring-webflux