【问题标题】:Spring Eureka looking for default port 8761 instead of custom portSpring Eureka 寻找默认端口 8761 而不是自定义端口
【发布时间】:2019-11-15 13:29:23
【问题描述】:

我有一个 Spring Boot Eureka 服务器应用程序,该应用程序配置为在端口 5000 中运行,而不是默认的 8761 端口。但是,当我运行 SBA 时,我在控制台上收到一些与 java connection denied 相关的错误,同时收听 localhost :8761

INFO 10408 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : 从 eureka 服务器获取所有实例注册信息 ERROR 10408 --- [tbeatExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : 请求执行错误。端点=默认端点{ serviceUrl='http://localhost:8761/eureka/}

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException:连接被拒绝:连接在 com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]

稍后当我调出其他微服务时,我可以看到它们已正确注册到运行在端口 5000 上的 eureka 中。但是为什么应用程序在启动 Eureka 服务器时忽略了配置呢?

从嵌入的图片也可以看出,服务器正在 8761 中寻找已注册和不可用的副本。

非常感谢对此的任何解释。

【问题讨论】:

  • 请提供您对客户的确认
  • 我在这个项目中错过了使用 Eureka 属性进行的自我搜索/注册为 false。正确答案如下。

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


【解决方案1】:

即使将 registerWithEureka & fetchRegistry 添加为 false,它仍然指向 8761 作为副本 url。

eureka.client.registerWithEureka = false 
eureka.client.fetchRegistry = false

问题的根本原因实际上并不是将自注册/搜索注册表属性设置为 false,而是修改/指定了正确的 serviceUrl 属性。

在 application.properties 中添加了以下行,现在我的 Eureka 服务器没有指向注册副本 url 的默认 Eureka 端口 8761。

eureka.client.serviceUrl.defaultZone: http://localhost:${server.port}/eureka/

【讨论】:

    【解决方案2】:
    Default port for eureka server is 8761 but you can override it using server.port property in application.properties file or application.yml file. 
    
    For e.g.
    (application.properties)
       server.port=5000 
    (application.yml)
       server:   
        port: 8761
    
    One more thing, you need to specify following properties too to avoid auto registration of eureka.
    
    **application.properties file:-**
    
    eureka.client.registerWithEureka = false
    eureka.client.fetchRegistry = false
    
    **application.yml file :-** 
    
    eureka:
       client:
          registerWithEureka: false
          fetchRegistry: false
    
    It should start your application on port 5000. If you still face any issues, just show your properties or yml file code here.
    

    【讨论】:

      【解决方案3】:

      请像下面这样配置 eureka 服务器。 eureka 服务器也将充当 eureka 客户端。所以服务器尝试将自己注册为客户端并寻找默认端口 8761。

      server:
        port: 9000
      
      eureka:
        client:
          register-with-eureka: false
          fetch-registry: false
          service-url:
            defaultZone: http://localhost:9000/eureka
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-10-23
        • 2018-01-18
        • 2019-08-11
        • 1970-01-01
        • 1970-01-01
        • 2019-03-10
        • 1970-01-01
        • 2014-02-08
        相关资源
        最近更新 更多