【问题标题】:spring-boot-starter-web-reactive M4 dependencyspring-boot-starter-web-reactive M4 依赖
【发布时间】:2017-06-17 03:06:22
【问题描述】:

Spring web 响应式中有一个 WebClient and ClientRequest 类。如果我们查看以下文档,可以使用 WebClient 来使用 ClientRequest。

WebClient client = WebClient.create(new ReactorClientHttpConnector());
ClientRequest<Void> request =      ClientRequest.GET("http://example.com/resource").build();

Mono<String> result = client
 .exchange(request)
 .then(response -> response.bodyToMono(String.class));

但不幸的是,ClientRequest.GET 方法不适用于我添加到项目中的 gradle 依赖项。下面是我正在使用的 gradle 依赖:

    dependencies {
    compile('org.springframework.boot.experimental:spring-boot-starter-web-reactive')
    compile('org.springframework.cloud:spring-cloud-starter-eureka')
    compile('org.springframework.boot:spring-boot-starter-hateoas')
    compile('io.reactivex:rxjava')
    compile('io.reactivex:rxjava-reactive-streams')
    //Spring Test case dependency
    testCompile("org.springframework.boot:spring-boot-starter-test")
    testCompile('io.rest-assured:rest-assured:3.0.1')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Dalston.BUILD-SNAPSHOT"
        mavenBom "org.springframework.boot.experimental:spring-boot-dependencies-web-reactive:0.1.0.BUILD-SNAPSHOT"
    }
}

我找不到 M4 的依赖项。 M4 是否在任何存储库的某个地方发布?

【问题讨论】:

    标签: java spring-boot spring-webflux


    【解决方案1】:

    这个 Spring Boot 启动器依赖于当前的 Spring Framework 5.0 SNAPSHOT。 WebClient API 最近发展了,the reference documentation should be up-to-date

    现在可以编写您的示例:

    WebClient client = WebClient.create("http://example.com/");
    
    Mono<String> result = client
      .get("/resource")
      .exchange()
      .then(response -> response.bodyToMono(String.class));
    

    【讨论】:

    • 感谢@Brain 的回复。我能够使用 WebClient 但现在还有另一个问题。当远程服务有错误响应时,它不提供远程服务发送的数据。我正在从我的反应式休息控制器调用微服务,如果出现错误,它只会将 HttpStatus 传递给我的休息控制器。你可以在这里找到详细信息stackoverflow.com/questions/42045267/…
    【解决方案2】:

    您需要配置正确的存储库。 M4 即里程碑项目与通用版本不在同一个存储库中。事实上,Spring 也为它提供了单独的存储库,用于快照发布。检查Spring Repositories

    对于里程碑版本,请使用以下存储库:

    buildscript {
        repositories {
            jcenter()
            maven { url 'http://repo.spring.io/milestone' }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-23
      • 2018-03-10
      • 2018-03-01
      • 2017-05-12
      • 2016-01-29
      • 1970-01-01
      • 2017-02-19
      • 2015-12-28
      • 2018-01-10
      相关资源
      最近更新 更多