当前位置:  开发笔记 > 前端 > 正文

Spring Cloud:Zuul投掷"负载均衡器没有可用于客户端的服务器"

如何解决《SpringCloud:Zuul投掷"负载均衡器没有可用于客户端的服务器"》经验,为你挑选了1个好方法。

我试图让一个简单的微服务注册到Eureka服务器,然后让Zuul代理到微服务.我得到微服务注册到Eureka服务器.但是,每当我带上Zuul服务时,我都会看到它没有注册到Eureka服务器.每当我尝试路由到微服务时,我得到以下异常:

负载均衡器没有可用于客户端的服务器:microservice

我无法弄清问题在哪里.任何帮助将不胜感激

下面是我对每个组件的Spring Boot类.

微服务组件

MicroserviceApplication.java

@SpringBootApplication(scanBasePackages = { "some.package.controller", "some.package.service" })
@EnableEurekaClient
@EnableJpaRepositories("some.package.repository")
@EntityScan("some.package.entity")
public class MicroserviceApplication {

    public static void main(String[] args) {
        SpringApplication.run(MicroserviceApplication.class, args);
    }

}

bootstrap.yml

server:
  port: 8090

info:
  component: Core Services

spring:
  application:
    name: microservice

application.yml

eureka:
  instance:
    leaseRenewalIntervalInSeconds: 1
    leaseExpirationDurationInSeconds: 2
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
    healthcheck:
      enabled: true
    lease:
      duration: 5

#some other logging and jpa properties below

Eureka服务器组件

EurekaServerApplication.java

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

}

bootstrap.yml

spring:
  application:
    name: discovery-server

application.yml

server:
  port: 8761

info:
  component: Discovery Server

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  instance:
    hostname: localhost
  server:
    waitTimeInMsWhenSyncEmpty: 0

API网关组件

ZuulGatewayApplication.java

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

    @Bean
    public ZuulGatewayPreFilter gatewayPreFilter() {
        return new ZuulGatewayPreFilter();
    }
}

bootstrap.yml

spring:
  application:
    name: api-gateway

application.yml

server:
  port: 8888

info:
  component: API Gateway

eureka:
  instance:
    leaseRenewalIntervalInSeconds: 1
    leaseExpirationDurationInSeconds: 2
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

zuul:
  routes:
    microservice: 
      path: /microservice/**
      serviceId: microservice

Sayantan.. 5

添加@EnableEurekaClient解决了这个问题.Zuul应用程序现在可以在Eureka服务器中被发现,并且能够路由请求.



1> Sayantan..:

添加@EnableEurekaClient解决了这个问题.Zuul应用程序现在可以在Eureka服务器中被发现,并且能够路由请求.

推荐阅读
Chloemw
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有