【问题标题】:Spring RestTemplate Client - connection refused exceptionSpring RestTemplate Client - 连接被拒绝异常
【发布时间】:2013-12-18 00:02:43
【问题描述】:

我是 web 服务的新手,正在尝试使用 RestTemplate 编写 RESTFul web 服务的客户端。 我使用 org.springframework.http.converter.xml.MarshallingHttpMessageConverter 作为消息转换器,使用 org.springframework.oxm.xstream.XStreamMarshaller 作为编组器。

有没有办法进一步调试或找出这个问题的根本原因?

我的消费者类看起来像这样 -

@SuppressWarnings("unchecked")
public List<Deal> getClientInformation() throws RestClientException {
    return restTemplate.getForObject(webServiceURL, List.class);

}

例外:

Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:359)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:307)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:177)
at main.java.com.sample.consumer.DealConsumer.getClientInformation(Consumer.java:35)
at main.java.com.client.WebserviceConsumerTestClient.main(WebserviceConsumerTestClient.java:16)

原因:java.net.ConnectException:连接被拒绝:连接 在 org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:359)

【问题讨论】:

    标签: web-services spring rest client


    【解决方案1】:

    您尝试调用的 webServiceURL 无法访问。确保 webServiceURL 路径正确且正在侦听。

    附言。还要检查服务器端是否存在防火墙问题。

    Wireshark 可以帮助您进一步调试。

    http://www.wireshark.org/

    【讨论】:

    • 谢谢,是的,这是防火墙问题。我能够通过在客户端代码中点击 web 服务之前添加以下两行来解决此错误。 System.setProperty("proxyHost", "yourproxy.server.com"); System.setProperty("proxyPort", "8080");
    • 好极了,现在如果问题得到解决,您可以通过将答案标记为正确来关闭此问题。
    • @dhamibirendra 谢谢。
    • @dhamibirendra 在“org.springframework.web.client.ResourceAccessException: I/O error on GET request for "”的情况下怎么办: 连接超时; 嵌套异常是 java.net.SocketTimeoutException"
    • @Sam,您尝试连接的 URL 似乎无法访问。你能ping通网址吗?如果该 URL 无法访问,请联系您的网络管理员或负责将该 URL 暴露给您的系统的人员。
    猜你喜欢
    • 1970-01-01
    • 2014-10-13
    • 1970-01-01
    • 2016-06-24
    • 2016-02-18
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多