繁体   English   中英

Spring 引导应用程序在 Eureka 服务器中显示为未知

[英]Spring Boot Application shown as UNKNOWN in Eureka server

我正在运行一个带有 Spring 的应用程序(作为 Discovery Client 应用程序),还有一个带有 Eureka 的 Discovery Server 和 Spring Cloud Config Server。 当客户端应用程序启动时,它在 Eureka 中注册为“UNKNOWN”,尽管其状态设置为“UP”,但无法从配置服务器获取属性。

客户端应用程序、尤里卡服务器和配置服务器 Spring 引导版本:2.4.2

客户端 bootstrap.properties:

spring.application.name=config-client-app
spring.cloud.config.discovery.enabled=true
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
eureka.instance.instance-id=${spring.application.name}

客户端application.properties文件:

logging.level.=debug
server.port=8900
eureka.client.healthcheck.enabled=true

客户申请Class:

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class ConfigClientAppApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(ConfigClientAppApplication.class, args);
    }
}

尤里卡服务器属性文件:

spring.application.name=discovery-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

尤里卡申请 class:

@EnableEurekaServer
@SpringBootApplication
public class DiscoveryServerApplication {

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

日志信息:

restartedMain] c.n.discovery.InstanceInfoReplicator     : InstanceInfoReplicator onDemand update allowed rate per min is 4
2021-02-09 16:02:50.388  INFO 2845 --- [  restartedMain] com.netflix.discovery.DiscoveryClient    : Discovery Client initialized at timestamp 1612904570388 with initial instances count: 1
2021-02-09 16:02:50.390  INFO 2845 --- [  restartedMain] o.s.c.n.e.s.EurekaServiceRegistry        : Registering application UNKNOWN with eureka with status UP
2021-02-09 16:02:50.391  INFO 2845 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1612904570391, current=UP, previous=STARTING]
2021-02-09 16:02:50.391  INFO 2845 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_UNKNOWN/192.168.10.22:8900: registering service...
2021-02-09 16:02:50.391  WARN 2845 --- [  restartedMain] c.n.discovery.InstanceInfoReplicator     : Ignoring onDemand update due to rate limiter
2021-02-09 16:02:50.393  INFO 2845 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8900 (http) with context path ''
2021-02-09 16:02:50.394  INFO 2845 --- [  restartedMain] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8900
2021-02-09 16:02:50.413  INFO 2845 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_UNKNOWN/192.168.10.22:8900 - registration status: 204

我用的是Spring云版

<spring-cloud.version>2021.0.5</spring-cloud.version>

和 spring 引导版本

<version>2.7.5</version>

在 application.properties 中,添加以下行以解决错误:

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

默认情况下,Eureka 服务器将自己注册到发现中。 以下两行将告诉 eureka 服务器在这个上下文中只有一个 eureka 服务器存在。

如果没有这些,我们的 Eureka Server 将尝试在上下文中的其他 Eureka Server 上查找并注册自己,并抛出发现客户端异常。 即我们自己的系统。

如果在添加上述属性后遇到以下错误,只需添加以下属性即可。

如果不需要配置,我们必须将其添加到properties中。

spring.cloud.config.enabled=false

否则应用程序将抛出以下异常。

No spring.config.import property has been defined

(或)如果您有其他服务器,例如任何配置服务器,我们可以将此可选服务器配置添加到application.properties

spring.config.import=optional:configserver: Your server url

Spring Cloud Config 为分布式系统中的外部化配置提供服务器端和客户端支持

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM