首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当使用spring时,WebTestClient不起作用。

当使用spring时,WebTestClient不起作用。
EN

Stack Overflow用户
提问于 2017-08-01 08:45:15
回答 1查看 1.4K关注 0票数 0

我正在通过Spring 2.0.0.M3使用Spring。下面是我的项目的依赖项,

代码语言:javascript
复制
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,尽管我们使用的是默认情况下使用反应性网络的网络流量。

是弹簧引导测试的错误还是错误?

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

代码语言:javascript
复制
@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();
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-07 06:52:17

启动tomcat的错误是由测试依赖org.apache.qpid:qpid-broker:6.1.2引起的,它依赖于javax.serlvet-api:3.1破坏了tomcat的启动。

不包括下面的无用模块,使tomcat再次发射,

代码语言:javascript
复制
configurations {
    all*.exclude module: 'qpid-broker-plugins-management-http'
    all*.exclude module: 'qpid-broker-plugins-websocket'
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45433032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档