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

出现com.netflix.client.ClientException: Load balancer does not have available server for client:xxx这个报错

网上说增加配置ribbon.eureka.enabled=true, 对于我的没有用, 到最后发现自己的注册中心并没有起来,启动文件竟然没有增加@EnableEurekaServer注解,大家可以http://IP:host测试一下,如果没有eureka的页面就先检查一下自己的注册中心,不要和我犯同样的错误?

 

下面是成功的案例,可以参考一下

一、前景spring cloud 注册中心: eureka

1.对应pom.xml

<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

2.启动文件中增加

@EnableEurekaServer注解

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
       public static void main(String[] args) {
            SpringApplication.run(EurekaApplication.class, args);
       }
}

3.application.properties文件

server.port=8761
eureka.instance.hostname=localhhh
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
 

4.启动后可以测试一下你的注册中心有没有起来:http://localhhh:8761,出现下面页面则表示注册中心起来了

 

二、服务Producer(生产者)和服务Consumer(消费者):  feign

因为Producer和Consumer需要向Eureka注册和订阅服务,需要使用eureka客户端,pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>


spring-cloud-starter-netflix-eureka-client中支持ribbon路由,所以不需要再次设置,也不要忘记@EnableDiscoveryClient注解

eureka-client启动后都会注册到eureka-server, 可以刷新http://localhhh:8761查看, 希望可以有所帮助!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值