2

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

Environment:

  • Spring-Boot 2.1.4
  • Junit 5.4.0
  • spring-restdocs-webtestclient
  • spring-webflux

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.

Florian E.
  • 422
  • 4
  • 10
  • Why do you exclude Spring versions from the Sleuth dependency? – Marcin Grzejszczak Apr 09 '19 at 13:42
  • Very easy - I have Spring Boot 2.1.4 and spring-framework 5.1.6 and started with sleuth version 2.1.0 and this had different versions so I had a spring version mix. – Florian E. Apr 09 '19 at 15:41
  • Info: same behaviour if I remove all exclusion from the sleuth dependency – Florian E. Apr 09 '19 at 15:43
  • Why do you alter the spring versions at all? It should come from Boot. Also it would be good to have the full stacktrace or any additional pieces of information cause currently I don't know how to help you – Marcin Grzejszczak Apr 09 '19 at 15:44
  • ```spring-cloud-starter-sleuth``` come from springframework.cloud and have own dependency and is not part of spring-boot, but it make no differrence because without exclusions the same error occures. – Florian E. Apr 10 '19 at 07:29

3 Answers3

1

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.

Florian E.
  • 422
  • 4
  • 10
1

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.

Jan Nielsen
  • 329
  • 4
  • 9
0

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

tony hu
  • 81
  • 1
  • 3