title: Spring WebClient as an alternative to RestTemplate
body: <p>The current javadoc of RestTemplate states:</p>
  
  <blockquote>
    <p>NOTE: As of 5.0, the non-blocking, reactive org.springframework.web.reactive.client.WebClient offers a modern alternative to the RestTemplate with efficient support for both sync and async, as well as streaming scenarios. The RestTemplate will be deprecated in a future version and will not have major new features added going forward.</p>
  </blockquote>
  
  <p>We are writing a new project using spring boot 2.0.6 and spring 5.0.10. </p>
  
  <p>Seeing that restTemplate is going to be deprecated we decided to use the new WebClient which should have support for synch calls as well. But I couldn't find any documentation on how that should be achieved. </p>
  
  <p>I have used block for this as in the code below:</p>
  
  <pre><code>ResponseEntity&lt;String&gt; response = webClient.get()
              .uri(url)
              .exchange()
              .flatMap(r -&gt; r.toEntity(String.class))
              .block();
  </code></pre>
  
  <p>However this is throwing the exception below when called from a spring controller</p>
  
  <pre><code>java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread
  </code></pre>
  
  <p>So how exactly should WebClient be used in a synchronous way?</p>
  
  <p>EDIT: My pom.xml looks like this:</p>
  
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-webflux&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
          &lt;artifactId&gt;spring-cloud-starter-config&lt;/artifactId&gt;
      &lt;/dependency&gt;
  </code></pre>