Spring RestTemplate Client - connection rejected exception

shstlldc  于 2024-01-05  发布在  Spring
关注(0)|答案(2)|浏览(107)

我是一个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:Connection refused:connect at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:359)

koaltpgm

koaltpgm1#

您尝试调用的webServiceURL无法访问。请确保webServiceURL路径正确并且正在侦听。
另外,请检查服务器端是否有防火墙问题。
Wireshark可以帮助您进一步调试。
http://www.wireshark.org/

j7dteeu8

j7dteeu82#

服务器未运行:确保https://localhost:1112上运行的服务器已启动并运行。您可以尝试直接从浏览器访问URL或使用curl等工具查看服务器是否响应。
正确网址:仔细检查URL端点(/erm-app/fetchOfcByLevel)并确保其正确。一个小的错别字或不正确的端点都可能导致连接错误。
SSL/TLS配置:由于您使用的是HTTPS,请确保服务器端的SSL/TLS配置设置正确,如果SSL/TLS握手出现问题,可能会导致连接被拒绝。
防火墙或网络限制:有时候,网络防火墙或其他安全配置可能会阻止连接到特定端口。请确保没有此类限制,可能会阻止您的连接。
地方发展:如果在同一台机器上运行客户端和服务器进行本地开发,请确保服务器实际上运行在端口1112上,并设置为接受连接。
访问&访问:查看服务端应用程序(https://localhost:1112)的日志。通常,服务端日志可以帮助我们了解拒绝连接的原因,以及服务端是否存在问题。
外部服务:如果您的Sping Boot 应用依赖于其他服务,请确保这些服务也在运行并可访问。

相关问题