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

  1. 使用 RestTemplate 调用 restful 服务

    什么是RestTemplate? RestTemplate是Spring提供的用于访问Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效 ...

  2. 使用 Spring RestTemplate 调用 rest 服务时自定义请求头(custom HTTP headers)

    在 Spring 3.0 中可以通过  HttpEntity 对象自定义请求头信息,如: private static final String APPLICATION_PDF = "app ...

  3. 调用远程主机上的 RMI 服务时抛出 java.rmi.ConnectException: Connection refused to host: 127.0.0.1 异常原因及解决方案

    最近使用 jmx 遇到一个问题,client/server 同在一台机器上,jmx client能够成功连接 server,如果把 server 移植到另一台机器上192.168.134.128,抛出 ...

  4. Eureka服务注册中心错误:com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect

    报错信息 14:43:45.484 [main] INFO com.netflix.discovery.DiscoveryClient - Getting all instance registry ...

  5. springCloud 服务注册启动报错<com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect>

    报错:com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: ...

  6. Redis 服务端配置——Could not connect to Redis at 127.0.0.1:6379: Connection refused

    [root@centoszang 桌面]# redis-cli Could : Connection refused Could : Connection refused not connected& ...

  7. Eureka服务注册中心相关错误com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect

    启动项目报错如下 原因: 在默认设置下,Eureka服务注册中心也会将自己作为客户端来尝试注册它自己,所以会出现 com.sun.jersey.api.client.ClientHandlerExce ...

  8. 阿里云配置通用服务的坑 ssh: connect to host 47.103.101.102 port 22: Connection refused

    1.~ wjw$ ssh root@47.103.101.102 ssh: connect to host 47.103.101.102 port 22: Connection refused ssh ...

  9. Weblogic 连接 RMI 服务报错 Connection refused

    WebLogic 连接 RMI 服务报错 Connection refused 访问 WebLogic RMI 服务报错,连接被拒绝,连接超时. 奇怪的是,报错的 host 根本不是我要访问的. 报错 ...

随机推荐

  1. P4868 Preprefix sum

    传送门 挺显然的一题?单点修改,前缀和数组前缀查询 树状数组就可以维护了 考虑每个位置对应询问的贡献,设询问的位置为 $x$,对于原数组 $a[i]$ 的某个位置 $i$,它会贡献 $(x-i+1)* ...

  2. Android 调用摄像头功能【拍照与视频】

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/ma_hoking/article/details/28292973 应用场景: 在Android开发 ...

  3. 一分钟理解sdk

    SDK 外语:Software Development Kit 中文:软件开发工具包 含义:一般都是一些软件工程师为特定的软件包.软件框架.硬件平台.操作系统等建立应用软件时的开发工具的集合. 通俗: ...

  4. Js和Jquery实现ajax长轮询

    众所周知,HTTP协议是无状态的,所以一次的请求都是一个单独的事件,和前后都没有联系.所以我们在解决网页实时聊天时就遇到一个问题,如何保证与服务器的长时间联系,从而源源不段地获取信息. 一直以来的方式 ...

  5. springmvc中的参数接收

    import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ...

  6. Mac下的常用快捷键总结

    由于在公司的时候是使用的Windows下进行开发工作,但是回家之后,有时候要使用自己的Mac进行开发等工作,那么流利的使用快捷键就变得尤其的重要. 1. 退出软件 cmd + q 2.将最前面的窗口最 ...

  7. 在Linux上安装tomcat和JDK

    1.tomcat的安装 a.#cd download(进入download文件夹) b.#wget http://111.23.5.142:82/mirrors.hust.edu.cn/apache/ ...

  8. python gRPC简单示例

    Ubuntu18.04安装gRPC protobuf-compiler-grpc安装 sudo apt-get install protobuf-compiler-grpc protobuf-comp ...

  9. Assets.xcassets的详细使用方法

    开始之前,首先回顾一下iOS7初体验(1)——第一个应用程序HelloWorld中的一张图,如下所示: 本文分享一下Images.xcassets的体验~_~ 1. 打开此前使用过的HelloWorl ...

  10. Django新建第一个投票应用

    1:在Pycharm的命令端口,确保执行文件路径是与mysite同级 $ python3 manage.py startapp polls 系统会自动生成polls应用的目录,其结构如下 polls/ ...