zoukankan      html  css  js  c++  java
  • RestTemplate 调用本地服务 connection refused

    当需要使用服务间的互相调用的时候,通常来说最优雅的方式莫过于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了。



  • 相关阅读:
    刘翔那点事
    网站建站模板
    搞笑!from 饮水思源
    我de虚拟经济学系列第一章 经济危机拼命建桥
    IT民工系列——c#操作Microsoft IE,实现自动登录吧!
    商业智能的发展及其应用
    我de虚拟经济学系列第三章 常见的致富之路
    IT民工系列——c#操作EditGrid,自己做一个在线Excel数据库吧!
    Asp.net下的Singleton模式
    asp.net 控件功能小结
  • 原文地址:https://www.cnblogs.com/goblinn/p/10882527.html
Copyright © 2011-2022 走看看