无法自动连线`WebTestClient`-没有自动配置 [英] Cant autowire `WebTestClient` - no auto configuration
问题描述
我们正在使用spring框架5和spring boot 2.0.0.M6,我们也在使用WebClient
进行反应式编程.我们为反应性休息端点创建了测试方法,因此我查找了一些有关如何执行此操作的示例.我发现这以及其他很多都相同的地方.他们只是自动连接WebTestClient
.所以我尝试了相同的方法:
We are using spring framework 5 and spring boot 2.0.0.M6 and we are also using WebClient
for reactive programming. We created test methods for our reactive rest endpoints and so I looked up for some example on how to do it. I found this one or this and many others which where all the same. They just autowire a WebTestClient
. So I tried the same:
@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);
}
}
我无法运行它,因为出现错误:
I cannot run this because I get the error:
Could not autowire. No beans of 'WebTestClient' type found.
因此,似乎没有自动配置存在.我使用的是错误版本还是什么问题?
So it does not seem that there is a auto configuration existing. Do I use the wrong version or what is the matter here?
推荐答案
使用@AutoConfigureWebTestClient
批注注释您的MyControllerTest
测试类.那应该可以解决问题.
Annotate your MyControllerTest
test class with @AutoConfigureWebTestClient
annotation. That should solve the issue.
这篇关于无法自动连线`WebTestClient`-没有自动配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!