Eureka restTemplate访问超时

时间:2023-03-09 06:37:33
Eureka restTemplate访问超时

错误代码

I/O error on GET request for "http://sushibase/v1/Publich/authorize": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect

  

错误现象:明明在Eureka上注册成功的服务,但无法通过服务名进行访问

网上的解决方案:

网上有一种解决方案是说在restTemplate上面加注解

@LoadBalanced

但是我加了没有作用,依然timeout

调试源码,发现问题:

Eureka restTemplate访问超时

调试源码后发现sushiBase这个服务,在eureka上注册的竟然是一个内网ip

最终解决方案

在eureka客户端的配置文件中加入以下内容:

# 指定此实例的ip

eureka.instance.ip-address=
# 注册时使用ip而不是主机名
eureka.instance.prefer-ip-address=true

参考:https://www.cnblogs.com/moonandstar08/p/7571610.html