代码之家  ›  专栏  ›  技术社区  ›  kaushik

Spring Webclient:illegalargumentexception没有足够的变量来展开“comment\u count”

  •  0
  • kaushik  · 技术社区  · 7 年前

    但是,得到这个例外

    java.lang.IllegalArgumentException: Not enough variable values available to expand reactive spring
    

    代码段:

    import org.springframework.stereotype.Component;
    import org.springframework.web.reactive.function.client.WebClient;
    
    import reactor.core.publisher.Mono;
    
    @Component
    public class Stackoverflow {
    
        WebClient client = WebClient.create();
    
        public Mono<Post> fetchPost(String url) {
            // Url contains "comments{comment_count}"
            return client.get().uri(url).retrieve()
                    .bodyToMono(Post.class);
        }
    }
    

    我知道restemplate的解决方案,但我需要使用spring webclient。

    0 回复  |  直到 7 年前
        1
  •  5
  •   yash sugandh    7 年前

    您可以使用UriComponentsBuilder创建URL,如下所示

     webClient.get().uri(getFacebookGraphURI(3)).retrieve().bodyToMono(Object.class);
    
    private URI getFacebookGraphURI(int comments){
       return UriComponentsBuilder.fromHttpUrl("https://graph.facebook.com")
            .pathSegment("v3.2", "PAGE_ID", "posts").queryParam("fields", "comments{comment_count}")
            .queryParam("access_token", "acacaaac").build(comments);
    
      }
    

    或者

    https://graph.facebook.com ") .queryParam(“访问令牌”,“acacaac”).build().toString(),commentsCount).retrieve().bodyToMono(Object.class);