首页 > 其他 > 详细

RestTemplate 调用本地服务 connection refused

时间:2019-05-17 17:31:28      阅读:1339      评论:0      收藏:0      [点我收藏+]

当需要使用服务间的互相调用的时候,通常来说最优雅的方式莫过于Feign调用了。但是有时候特殊原因还是需要使用httpClient之类的工具。

本次我在使用RestTemplate调用本地服务的时候,会出现如下错误:

Servlet.service() for servlet [dispatcherServlet] in context with path [] 
threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException:
I/O error on GET request for "https://xx/xx/xx": Connect to xx:xx [xx/xx] failed:
Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException:
Connect to xx:xx [xx/xx] failed: Connection refused (Connection refused)]
with root cause

用同样的代码调用其他服务器上的服务时并未出现这样的错误,曾一度怀疑是url有误,然而浪费了很多时间去尝试这个。然后又怀疑是网关,或防火墙阻拦了?,然而又浪费了很多时间。

刷了会微博冷静了下,才想起来可能是url地址的写法有误。

当调用本地服务的时候,url应该写成

https://localhost:xx/xx/xx

(我想应该也可以写成服务名代替ip的那种吧,)

然而,改完之后,还是有问题,不过还好的是错误变了:

 

org.springframework.web.util.NestedServletException: Request processing failed; 
nested exception is org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://localhost:xx/xx/xx":
Unrecognized SSL message, plaintext connection?; nested exception is javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

这个错是使用https请求了http服务,很好改:

http://localhost:xx/xx/xx

 

o了。



RestTemplate 调用本地服务 connection refused

原文:https://www.cnblogs.com/goblinn/p/10882527.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!