宋子宪博客

Szx

Spring Cloud报错No instances available for localhost解决
负载均衡ribbon,在加入@LoadBalanced启动后就报错No instances available f...
扫描右侧二维码阅读全文
08
2019/05

Spring Cloud报错No instances available for localhost解决

负载均衡ribbon,在加入@LoadBalanced启动后就报错No instances available for localhost,此处rest请求如下:
Spring Cloud报错No instances available for localhost解决1.png

注册到eureka之后,不能这样用,改为注册的服务名即可:
Spring Cloud报错No instances available for localhost解决2.png

Last modification:June 26th, 2019 at 01:44 am
如果觉得这篇技术文章对您有帮助,可以请博主喝一杯饮料

One comment

  1. wang charle

    负载均衡出问题了。自定义一个(主要是为了防止与系统的RestTemplate冲突) 试试:
    class NonLoadBalancedRestTemplate extends RestTemplate {
    public NonLoadBalancedRestTemplate(OkHttp3ClientHttpRequestFactory o) {
    super(o);
    }
    }
    然后注入(注意:千万不要给bean加上@LoadBalanced注解, 因为系统默认的负载均衡选择微服务实例时会出错, 返回空的实例)
    @Bean
    public NonLoadBalancedRestTemplate nonLoadBalancedRestTemplate() {
    return new NonLoadBalancedRestTemplate(new OkHttp3ClientHttpRequestFactory());
    }

Leave a Comment