Java 如何让WebTestClient注销所有请求

Java 如何让WebTestClient注销所有请求,java,spring,spring-mvc,spring-test,spring-webflux,Java,Spring,Spring Mvc,Spring Test,Spring Webflux,我的SpringBootTest设置如下 @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class ControllerTest { @Autowired private WebTestClient webTestClient; @Test public void postTest()

我的SpringBootTest设置如下

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

    @Autowired
    private WebTestClient webTestClient;

    @Test
    public void postTest() {
        // Setup data
        Form form = new Form();
        form.setName("Test1");
        form.setDescription("Description1");

        // Run method
        webTestClient.post()
                .uri("/api/v1/data")
                .contentType(MediaType.APPLICATION_JSON)
                .accept(MediaType.APPLICATION_JSON)
                .syncBody(form)
                .exchange()

                .expectStatus()
                .isOk()

                .expectBody()
                .jsonPath("data.id").isNotEmpty()
                .jsonPath("data.name").isEqualTo(form.getName())
                .jsonPath("data.description").isEqualTo(form.getDescription())
                .jsonPath("data.status").isEqualTo("A");
    }
}
我无法找到让
WebTestClient
注销所有HTTP请求和响应的方法

我想将
WebTestClient
保留为
@Autowired
。我可能可以创建某种应用程序配置或配置类来实现这一点,但不幸的是,我还没有发现如何使用。请看这篇文章


使用注册的筛选器创建您自己的客户端,它应该可以工作。

@thomas77问题在于,他们正在手动实例化
WebTestClient
,而我想保留它
@Autowired
。问题在于,他们正在手动实例化
WebTestClient
,而我想保留它
@Autowired
在中,它应该作为bean在
@Configuration
类中创建和配置,以便可以自动连接?您有创建bean的Spring配置吗?如果是这样,请将它与
@Bean
注释放在一起。