【问题标题】:Eureka client exception com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known serverEureka 客户端异常 com.netflix.discovery.shared.transport.TransportException:无法在任何已知服务器上执行请求
【发布时间】:2018-12-24 09:55:34
【问题描述】:

我是微服务新手。我正在尝试创建一个用于学习目的的小型应用程序。这是我的代码: EurekaServer - application.yml

    spring:
     application:
      name: EurekaServer

    server:
     port: 8080
     servlet:
      context-path: /EurekaServer

    eureka:
     client:
      fetch-registry: false
      register-with-eureka: false 

Eureka Server 工作正常,我可以在http://localhost:8080/EurekaServer 看到仪表板

EmployeeClient:application.yml 如下:

    spring:
     application:
      name: EmployeeClient

    server:
     port: 8586

    eureka:
     client: 
      serviceUrl:
       defaultZone: http://localhost:8080/EurekaServer

在最后一行中,我需要明确编写 serviceUrl,因为在 sts 中按 ctrl+space 时它不显示选项 serviceUrl,但它显示 service-url,连字符号。与 defaultZone 相同。我是否缺少某些 jar 或特定版本?

我的 EmployeeClientApplication.java

    @EnableEurekaClient
    @SpringBootApplication
    public class EmployeeClientApplication {

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

当我尝试运行 EmployeeClientApplication.java 时,出现以下异常:

    com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

我也尝试使用@EnableDiscoveryClient 代替@EnableEurekaClient,但没有成功。

EmployeeClient pom.xml 的一部分如下:

    <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>2.0.3.RELEASE</version>
       <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      <java.version>1.8</java.version>
      <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
    </properties>

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

我哪里出错了?

【问题讨论】:

    标签: spring-boot microservices spring-cloud netflix-eureka


    【解决方案1】:

    如果您在服务器的应用程序属性文件中添加了 DiscoveryServer 作为应用程序名称,则添加 eureka.instance.hostname=localhost 可以解决您的问题。

    【讨论】:

    • 你可以在下面查看我的答案。
    • 我已经添加了该属性,但得到了上面给出的错误!
    【解决方案2】:

    我必须在 EmployeeClient application.yml 中使用下面的行

        defaultZone: http://localhost:8080/EurekaServer/eureka
    

    【讨论】:

      【解决方案3】:

      我认为,您必须将客户端属性中的默认区域从 /EurekaServer 更改为 /eureka

      eureka:
           client: 
            serviceUrl:
             defaultZone: http://localhost:8080/eureka
      

      "/eureka" 是将服务注册到 eureka 注册表的其余端点。 进行更改并尝试,它应该可以工作。

      除此之外,如果您愿意更改 UI 仪表板 url,您应该使用 eureka.dashboard.path 属性。

      【讨论】:

      • 是的,你的回答对了一半,它给了我一个想法。我在下面回答。 +1为您的答案。谢谢朋友。
      猜你喜欢
      • 2018-02-18
      • 2020-04-03
      • 2021-04-19
      • 1970-01-01
      • 2020-05-22
      • 2018-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多