Spring RestTemplate Client - 连接被拒绝异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11648706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 05:16:23  来源:igfitidea点击:

Spring RestTemplate Client - connection refused exception

web-servicesspringrestclient

提问by PST

I am new to webservices and trying to write a RESTFul webservice's client using RestTemplate. I am using org.springframework.http.converter.xml.MarshallingHttpMessageConverter as message converter and org.springframework.oxm.xstream.XStreamMarshaller as marshaller.

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

Is there any way to debug this further or find out the root cause of this issue?

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

My consumer class looks like this -

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

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

}

}

Exception :

例外 :

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)

Caused by: java.net.ConnectException: Connection refused: connect at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:359)

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

回答by dhamibirendra

the webServiceURL you are trying to call is not reachable. Ensure the webServiceURL path is correct and is listening.

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

PS. Also check if there is some firewall issue at Server side.

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

Wireshark may help you to debug further.

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

http://www.wireshark.org/

http://www.wireshark.org/