No instances available for SPRINGCLOUD-PROVIDER-DEPT(Ribbon负载均衡)报错解决方案

第一步

eureka3.0以上的版本包含ribbon所以不需要在导入ribbon的依赖了,所以要删掉ribbon的依赖

第二步

在application.yaml配置中加入 fetch-registry: true  

fetch-registry必须是true,不能是false,为true时的意思是表示检索注册中心的所有服务。如果为false则无法发现服务

# Eureka 配置
eureka:
  client:
    register-with-eureka: false #不向Eureka注册自己
    service-url:
      defaultZone: http://localhost:7001/eureka/
    # defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/
    fetch-registry: true  #为true时的意思是表示检索注册中心的所有服务。如果为false则无法发现服务

其他配置

设计一个config包在下面配置一个ConfigBean类,用来消费者调用服务者的controller

@Configuration
public class ConfigBean {//@Configuration  --  相当于spring中的 applicationContext.xml

    //配置负载均衡实现RestTemplate
    @Bean
    @LoadBalanced //Ribbon
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
}

在启动类上加入 @EnableEurekaClient //Eureka客户端

@SpringBootApplication
@EnableEurekaClient //Eureka客户端
public class DeptConsumer_80 {
    public static void main(String[] args) {
        SpringApplication.run(DeptConsumer_80.class,args);
    }
}

客户端依赖

        <!--加入eureka客户端依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

服务端依赖

<!--加入eureka服务端依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我认不到你

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值