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了。




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM