将Spring-cloud-starter-sleuth依赖项添加到Spring-Boot应用程序中,一些Rest Doc测试失败

问题描述 投票:0回答:2

我有一个Spring-Boot 2.1.4应用程序,带有用于Flux控制器的n-RestDoc测试。

环境:

  • Spring-Boot 2.1.4
  • Junit 5.4.0
  • 弹簧restdocs-webtestclient
  • 弹簧webflux

如果我将spring-cloud-starter-sleuth依赖项添加到应用程序中,则某些doc测试会在maven构建中失败。在不同环境下重要的不同测试类失败:

java.lang.IllegalStateException: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@6516dd09 has been closed already ....

如果使用maven qazxsw poi运行失败测试而不是测试不会失败,那么如果指定了一组(不是全部)测试。

依赖

-Dtest=OptDocTest

所有测试看起来都相似

<dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-sleuth</artifactId>
     <version>2.1.1.RELEASE</version>
     <exclusions> <!-- exclude old spring versions -->
          <exclusion>
               <artifactId>*</artifactId>
               <groupId> org.springframework.security</groupId>
           </exclusion>
           <exclusion>
                <artifactId>spring-aop</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
      </exclusions>
</dependency>
<dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
</dependency>

使用正在运行的引导应用程序的所有IT测试都正常

我不知道出了什么问题,为什么@ExtendWith({ RestDocumentationExtension.class, SpringExtension.class }) @AutoConfigureRestDocs("target/generated-snippets") @SpringBootTest(//webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { ArchimedesApplication.class }) class OptControllerDocTest { @MockBean private SrkConnector srkTConnector; @Autowired private ApplicationContext context; private WebTestClient webTestClient; @BeforeEach void beforeEach(RestDocumentationContextProvider restDocumentation) { this.webTestClient = WebTestClient.bindToApplicationContext(context) .configureClient() .filter(documentationConfiguration(restDocumentation)) .build(); } @Test void documentationTest() throws IOException { this.webTestClient.post() .uri("/opt") .contentType(MediaType.APPLICATION_JSON) .body(BodyInserters.fromObject(testRequest)) .exchange() .expectStatus() // here the error occur .isOk() .expectBody() ... } 关闭了。

在Windows机器上,具有助焊剂内容的控制器的其余doc测试在具有单声道内容的控制器的linux机箱上失败。

spring-boot spring-webflow spring-cloud-sleuth spring-restdocs
2个回答
0
投票

如果我在版本2.1.0.RELEASE中回退到AnnotationConfigReactiveWebServerApplicationContext并删除所有排除项,它就会被解决。

spring-cloud-starter-sleuth

如果我使用版本2.1.1.RELEASE错误发生。


0
投票

我也见过同样的问题。我通过将侦探降级为<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-sleuth</artifactId> <version>2.1.0.RELEASE</version> </dependency> 解决了这个问题(2.1.0也不适用于我)。 Mine Spring Boot版本是2.0.3.RELEASE。 如果2.0.3仍然不适合您,请尝试从2.0.5.RELEASE更多降级版本

© www.soinside.com 2019 - 2024. All rights reserved.