1

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));

但不幸的是,我添加到项目中的 gradle 依赖项无法使用ClientRequest.GET方法。以下是我正在使用的 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 是否在任何存储库的某个地方发布?

4

2 回答 2

0

这个 Spring Boot starter 依赖于当前的 Spring Framework 5.0 SNAPSHOTs。WebClientAPI 最近发展了,参考文档应该是最新的

你的例子现在可以写成:

WebClient client = WebClient.create("http://example.com/");

Mono<String> result = client
  .get("/resource")
  .exchange()
  .then(response -> response.bodyToMono(String.class));
于 2017-02-05T12:03:26.033 回答
0

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

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

buildscript {
    repositories {
        jcenter()
        maven { url 'http://repo.spring.io/milestone' }
    }
}
于 2017-11-10T06:28:47.237 回答