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' 
} 
相關問題