Florian E.
Florian E.

Reputation: 422

Adding spring-cloud-starter-sleuth dependency to a Spring-Boot App some of the Rest Doc test failing

I have a Spring-Boot 2.1.4 application with n-RestDoc tests for Flux controller.

Environment:

If I add the spring-clout-starter-sleuth dependendcy to the app, some of the doc test fails in maven build. Important on different environment different test classes fails with:

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

If run the failling test with maven -Dtest=OptDocTest than the test will not fail, also if a set (not all) test where specified.

Dependendcy

<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>

All test looks simular

@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() ...
    }

All IT Test with a running Boot Application works correct.

I have no idea what goes wrong and why the AnnotationConfigReactiveWebServerApplicationContext is closed.

On a windows box the rest doc test for controller with a flux content fails on a linux box for controller with mono content.

Upvotes: 2

Views: 3169

Answers (3)

Jan Nielsen
Jan Nielsen

Reputation: 351

This has been raised as a bug in the sleuth github issue list github.com/spring-cloud/spring-cloud-sleuth/issues/1450

If you, as me, have had this situation in regard to junit tests, then I solved it by removing all annotations @DirtiesContext in every junit test class I had in my project.

Upvotes: 1

tony hu
tony hu

Reputation: 81

Same issue I also met. I solved the issue by downgrade Sleuth to 2.0.3.RELEASE(2.1.0 also not work with me). Mine Spring Boot version is 2.0.5.RELEASE.
If 2.0.3 still not work for you, try more downgrade version from mvn repo

Upvotes: 0

Florian E.
Florian E.

Reputation: 422

It is solved if I fall back to spring-cloud-starter-sleuth in version 2.1.0.RELEASE and remove all exclusions.

<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-sleuth</artifactId>
      <version>2.1.0.RELEASE</version>
</dependency>

If I use version 2.1.1.RELEASE the error occur.

Upvotes: 1

Related Questions