0

我使用Spring webflux通过Spring引导2.0.0.M3。下面是我的项目的依赖,当使用spring-webflux时,WebTestClient不起作用

dependencies { 
compile 'org.springframework.boot:spring-boot-starter-actuator', 
     'org.springframework.cloud:spring-cloud-starter-config', 
     'org.springframework.cloud:spring-cloud-sleuth-stream', 
     'org.springframework.cloud:spring-cloud-starter-sleuth', 
     'org.springframework.cloud:spring-cloud-starter-stream-rabbit', 
     'org.springframework.boot:spring-boot-starter-data-mongodb-reactive', 
     'org.springframework.boot:spring-boot-starter-data-redis-reactive', 
     'org.springframework.boot:spring-boot-starter-integration', 
     "org.springframework.integration:spring-integration-amqp", 
     "org.springframework.integration:spring-integration-mongodb", 
     'org.springframework.retry:spring-retry', 
     'org.springframework.boot:spring-boot-starter-webflux', 
     'org.springframework.boot:spring-boot-starter-reactor-netty', 
     'com.fasterxml.jackson.datatype:jackson-datatype-joda', 
     'joda-time:joda-time:2.9.9', 
     'org.javamoney:moneta:1.0', 
     'com.squareup.okhttp3:okhttp:3.8.1', 
     'org.apache.commons:commons-lang3:3.5' 
compileOnly 'org.projectlombok:lombok:1.16.18' 
testCompile 'org.springframework.boot:spring-boot-starter-test', 
     'io.projectreactor:reactor-test', 
     'org.apache.qpid:qpid-broker:6.1.2', 
     'de.flapdoodle.embed:de.flapdoodle.embed.mongo' 
} 

应用程序是通过./gradlew bootRun运行良好,或直接运行主要的应用程序。

但是由于以下错误,我未能开始集成测试。

产生的原因:org.springframework.boot.web.server.WebServerException:无法启动Tomcat的嵌入式

我不知道为什么WebTestClient仍试图使用,即使我们是嵌入的Tomcat使用默认使用reactive-netty的webflux。

它是弹性引导测试的错误配置或错误?

下面是我的测试案例的代码片段,

@RunWith(SpringRunner.class) 
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 
public class NoteHandlerTest { 

@Autowired 
private WebTestClient webClient; 

@Test 
public void testNoteNotFound() throws Exception { 
    this.webClient.get().uri("/note/request/{id}", "nosuchid").accept(MediaType.APPLICATION_JSON_UTF8) 
      .exchange().expectStatus().isNotFound(); 
} 
} 

回答

0

推出的tomcat的错误是由测试依赖org.apache.qpid:qpid-broker:6.1.2,这取决于javax.serlvet-api:3.1断裂tomcat的启动引起的。

排除以下无用的模块,使Tomcat的再次启动,

configurations { 
    all*.exclude module: 'qpid-broker-plugins-management-http' 
    all*.exclude module: 'qpid-broker-plugins-websocket' 
} 
相关问题