【发布时间】:2019-10-17 18:50:08
【问题描述】:
我有一个 Spring-Boot 2.1.4 应用程序,其中包含用于 Flux 控制器的 n-RestDoc 测试。
环境:
- Spring-Boot 2.1.4
- Junit 5.4.0
- spring-restdocs-webtestclient
- spring-webflux
如果我将 spring-clout-starter-sleuth 依赖项添加到应用程序中,一些 doc 测试在 maven 构建中会失败。 在不同的环境中重要的是不同的测试类失败:
java.lang.IllegalStateException: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@6516dd09 has been closed already ....
如果使用 maven -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>
所有测试看起来都很相似
@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() ...
}
使用正在运行的启动应用程序进行的所有 IT 测试工作正常。
我不知道出了什么问题以及为什么AnnotationConfigReactiveWebServerApplicationContext 被关闭了。
在 windows 盒子上,带有通量内容的控制器的 rest doc 测试在带有单声道内容的控制器的 linux 盒子上失败。
【问题讨论】:
-
为什么要从 Sleuth 依赖中排除 Spring 版本?
-
非常简单 - 我有 Spring Boot 2.1.4 和 spring-framework 5.1.6 并从 sleuth 版本 2.1.0 开始,它有不同的版本,所以我有一个 spring 版本组合。
-
信息:如果我从 sleuth 依赖项中删除所有排除项,则行为相同
-
您为什么要更改 spring 版本?它应该来自 Boot。此外,最好有完整的堆栈跟踪或任何其他信息,因为目前我不知道如何帮助您
-
spring-cloud-starter-sleuth来自 springframework.cloud 并且有自己的依赖关系并且不是 spring-boot 的一部分,但它没有区别,因为没有排除会发生相同的错误。
标签: spring-boot spring-webflow spring-cloud-sleuth spring-restdocs