Java异常之解决com.netflix.client.ClientException: Load balancer does not have available server for client

本文目录

一、问题描述

二、错误原因

三、解决方案

方案1

方案2


一、问题描述

报错信息如下

Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: basic-iot-config
	at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483)
	at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184)
	at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180)
	at rx.Observable.unsafeSubscribe(Observable.java:10211)
	at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94)
	at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42)
	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
	at rx.Observable.subscribe(Observable.java:10307)
	at rx.Observable.subscribe(Observable.java:10274)
	at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:445)
	at rx.observables.BlockingObservable.single(BlockingObservable.java:342)
	at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:117)
	at org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient.execute(LoadBalancerFeignClient.java:63)
	... 33 common frames omitted

二、错误原因

在SpringCloud项目,会经常用一个服务a中调用另一个微服务b,明明启动了微服务b,但是却仍然报错

com.netflix.client.ClientException: Load balancer does not have available server for client: xxx

这时候,造成这种情况的原因基本上都是 两个服务注册到注册中心的端口不一样或者是注册到注册中心的服务名字不一致。

三、解决方案

方案1

方案1解决了此问题:

将两个服务(注册的服务和消费的服务)的名字改为一致即可,或者访问访问的URL改成一样的。

public class SystemConstant {
    /**
     * 应用名
     */
    public static final String APPLICATION_NAME = "back-operation-service-123";

}
spring:
  application:
    name: back-operation-service-123
    system: operation

 

方案2

在application.yml配置文件中添加

ribbon.eureka.enable: true

你可能感兴趣的:(异常解决方案,SpringBoot)