使用RestTemplate时报错java.lang.IllegalStateException: No instances available for 127.0.0.1

我在RestTemplate的配置类里使用了 @LoadBalanced
@Component
public class RestTemplateConfig {
@Bean
@LoadBalanced
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
或者


再调用
@Autowired
private RestTemplate restTemplate;
必须使用应用名作为代替ip:端口,
http://127.0.0.1:8080/user/get
改成
http://应用名/user/get
不然会报错
使用RestTemplate时报错java.lang.IllegalStateException: No instances available for 127.0.0.1

1:不要使用ip+port的方式访问,取而代之的是应用名
2:这种方式发送的请求都会被ribbon拦截,ribbon从eureka注册中心获取服务列表,然后采用均衡策略进行访问

原文地址:https://www.cnblogs.com/xiufengchen/p/10331366.html