首页 > 解决方案 > Kubernetes中的Spring Rest模板奇怪行为

问题描述

我在 Kubernetes(谷歌云)中有两个 Spring Boot 服务。

Service1 使用 org.springframework.web.client.RestTemplate 对使用 Service 名称的 Service2 执行 http 请求。在这两种情况下,Service1 都会收到以下错误:org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 org.springframework.web.client.ResourceAccessException: I/O error on POST request for " http://service1/tcp:/10.11.252.122:8080 ": Connection denied (Connection denied); 嵌套异常是 java.net.ConnectException: Connection denied (Connection denied)

当 10.11.252.122 为 Service2 集群 IP 时。

仅当 Service1 和 Service2 在同一个集群中时才会发生,在其他情况下代码可以正常工作。

什么会导致 Spring 将 tcp:/Cluser IP 添加到 url?

谢谢,

标签: springkubernetesresttemplate

解决方案


推荐阅读