• 我在使用eureka client消费者调用生产者的时候,出现以下问题:

java.lang.IllegalStateException: No instances available for eureka-server
就是 eureka-server服务不可用

  • 我的配置如下

服务注册中心配置:

server:
  port: 8760
spring:
  application:
    name: eureka-server
eureka:
  instance:
    hostname: 127.0.0.1
    prefer-ip-address: true
  client:
    service-url:
      defaultZone: http://${eureka.instance.hostname}:8760/eureka
    register-with-eureka: false
    fetch-registry: false

生产者配置:

server:
  port: 8761
spring:
  application:
    name: eureka-service
eureka:
  instance:
    hostname: localhost
  client:
    service-url:
      defaultZone: http://${eureka.instance.hostname}:8760/eureka

消费者配置:

server:
  port: 8762
spring:
  application:
    name: eureka-consumer
eureka:
  instance:
    hostname: localhost
  client:
    service-url:
      defaultZone: http://${eureka.instance.hostname}:8760/eureka
  • 出现“No instances available for eureka-server”原因及解决办法

由于netflix-eureka-client中已经集成了ribbon,所以导包的时候只要netflix-eureka-client这个就可以了。
这是我导入的依赖:

        <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-netflix-ribbon</artifactId>
            <version>2.2.9.RELEASE</version>
        </dependency>

去掉netflix-ribbon依赖即可解决问题

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

更多推荐

解决eureka client出现“No instances available for eureka-server”的问题