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.