尤里卡服务器未发现服务

时间:2018-09-11 11:12:11

标签: spring-boot spring-cloud

我刚刚开始通过Spring Cloud了解微服务,并从本文https://spring.io/blog/2015/07/14/microservices-with-spring开始尝试重现基本示例。这是我的代码:

Eureka服务器

@SpringBootApplication
@EnableEurekaServer
public class ServiceRegistryApplication {

  public static void main(String[] args) {
      System.setProperty("spring.config.name", "registration-server");
      SpringApplication.run(ServiceRegistryApplication.class, args);
  }
}

resources / registration-server.yml:

# Configure this Discovery Server
eureka:
  instance:
    hostname: localhost
  client:  # Not a client, don't register with yourself (unless running
           # multiple discovery servers for redundancy)
    registerWithEureka: false
    fetchRegistry: false

server:
  port: 1111   # HTTP (Tomcat) port

样品服务:

@SpringBootApplication
@EnableDiscoveryClient
public class AccountsServiceApplication {

  public static void main(String[] args) {
      System.setProperty("spring.config.name", "accounts-server");
      SpringApplication.run(AccountsServiceApplication.class, args);
  }
}

accounts-service.yml:

# Spring properties
spring:
  application:
     name: accounts-service

# Discovery Server Access
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:1111/eureka/

# HTTP Server
server:
  port: 2222   # HTTP (Tomcat) port

但是当我同时运行两个应用程序并转到localhost:1111时,我无法在应用程序列表中看到我的服务: enter image description here

您能给我打电话怎么办?

编辑

应用更改后,出现以下行: enter image description here

1 个答案:

答案 0 :(得分:0)

我为您提供了一个很好的解决方案,而且很简单

执行以下步骤:

1- Eureka服务器

@SpringBootApplication
@EnableEurekaServer
public class ServiceRegistryApplication {

  public static void main(String[] args) {

      SpringApplication.run(ServiceRegistryApplication.class, args);
  }
}

在application.properties中指定这些参数

spring.application.name=eureka-server
server.port=1111

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false 

2-在样品服务中

@SpringBootApplication
@EnableDiscoveryClient
public class AccountsServiceApplication {

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

在application.properties中指定这些参数

spring.application.name=accounts-service
server.port=2222

eureka.client.service-url.default-zone=http://localhost:1111/eureka

并且不要忘记删除所有.yml属性文件。