Spring RestTemplate客户端-连接被拒绝异常 [英] Spring RestTemplate Client - connection refused exception

查看:2374
本文介绍了Spring RestTemplate客户端-连接被拒绝异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

是否有任何方法可以进一步调试此问题或找出此问题的根本原因?

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 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:连接被拒绝:connect 在org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:359)

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

推荐答案

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

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

PS.另外,请检查服务器端是否存在防火墙问题.

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

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

Wireshark may help you to debug further.

http://www.wireshark.org/

这篇关于Spring RestTemplate客户端-连接被拒绝异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆