title: Spring RestTemplate timeout
body: <p>I would like to set the connection timeouts for a rest service used by my web application.  I'm using Spring's <code>RestTemplate</code> to talk to my service.  I've done some research and I've found and used the xml below (in my application xml) which I believe is meant to set the timeout.  I'm using Spring 3.0.</p>
  <p>I've also seen the same problem here <a href="https://stackoverflow.com/questions/9158465/timeout-configuration-for-spring-webservices-with-resttemplate">Timeout configuration for spring webservices with RestTemplate</a> but the solutions don't seem that <em>clean</em>, I'd prefer to set the timeout values via Spring config</p>
  <pre><code>&lt;bean id=&quot;RestOperations&quot; class=&quot;org.springframework.web.client.RestTemplate&quot;&gt;
      &lt;constructor-arg&gt;
      
        &lt;bean class=&quot;org.springframework.http.client.CommonsClientHttpRequestFactory&quot;&gt;
          &lt;property name=&quot;readTimeout&quot; value=&quot;${restURL.connectionTimeout}&quot; /&gt;
        &lt;/bean&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  </code></pre>
  <p>It seems whatever I set the <code>readTimeout</code> to be I get the following:</p>
  <p><strong>Network cable disconnected:</strong>
  Waits about 20 seconds and reports following exception:</p>
  <blockquote>
  <p><code>org.springframework.web.client.ResourceAccessException</code>: I/O error: No route to host: connect; nested exception is <code>java.net.NoRouteToHostException</code>: No route to host: connect</p>
  </blockquote>
  <p><strong>Url incorrect so 404 returned by rest service:</strong>
  Waits about 10 seconds and reports following exception:</p>
  <blockquote>
  <p><code>org.springframework.web.client.HttpClientErrorException</code>: 404 Not Found</p>
  </blockquote>
  <p>My requirements require shorter timeouts so I need to be able to change these.  Any ideas as to what I'm doing wrong?</p>
  <p>Many thanks.</p>