【问题标题】:Eureka server doesn't discover service尤里卡服务器没有发现服务
【发布时间】:2019-02-15 21:06:21
【问题描述】:

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

尤里卡服务器

@SpringBootApplication
@EnableEurekaServer
public class ServiceRegistryApplication {

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

资源/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 时,我在应用程序列表中看不到我的服务:

你能告诉我我做错了什么吗?

编辑

应用更改后,出现以下行:

【问题讨论】:

  • account-server != account-service 所以基本上你的配置会被忽略。
  • 请粘贴两个应用的服务器日志。
  • 很难说没有看到更多的应用程序(依赖项以及日志)。博客在这里有代码github.com/paulc4/microservices-demo你能发现任何区别吗?

标签: spring-boot spring-cloud


【解决方案1】:

我有一个很好的解决方案,而且很简单

按照以下步骤操作:

1- 尤里卡服务器

@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 属性文件。

【讨论】:

  • 感谢您的回复。我做了你在答案中写的所有更改,但服务仍然不在列表中。唯一的变化是出现了DS Replicas 行。 (我把截图放在评论里)
  • 在启动Services之前需要启动EurekaServer
猜你喜欢
  • 2019-09-26
  • 2019-09-04
  • 2016-08-02
  • 1970-01-01
  • 2019-11-16
  • 1970-01-01
  • 2018-04-15
  • 2017-09-23
  • 2018-10-23
相关资源
最近更新 更多