以编程方式使用Eureka客户端的问题-已完成DiscoveryClient的关闭 [英] Working With Eureka Clients Programmatically issue - Completed shut down of DiscoveryClient

查看:92
本文介绍了以编程方式使用Eureka客户端的问题-已完成DiscoveryClient的关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用复制创建了 Eureka服务器,现在尝试启动客户端.当我尝试启动spring-microservices-eureka-client时,出现以下错误.使用Spring Boot版本2.1.1.RELEASE.引导版本2.0.7.RELEASEFinchley.SR2也会出现相同的错误.

I've createde Eureka server with the replication and now trying to start the client. When I'm trying to start the spring-microservices-eureka-client, I get the below error. Using Spring Boot Version 2.1.1.RELEASE. The same error is coming with the Boot Version 2.0.7.RELEASE and Finchley.SR2.

2018-12-28 13:52:16.741  INFO 20236 --- [           main] o.s.c.n.e.s.EurekaServiceRegistry        : Registering application UNKNOWN with eureka with status UP
2018-12-28 13:52:16.742  INFO 20236 --- [           main] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1545985336742, current=UP, previous=STARTING]
2018-12-28 13:52:16.743  INFO 20236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org: registering service...
2018-12-28 13:52:16.749  INFO 20236 --- [           main] ringMicroservicesEurekaClientApplication : Started SpringMicroservicesEurekaClientApplication in 3.335 seconds (JVM running for 4.12)
2018-12-28 13:52:16.752  INFO 20236 --- [       Thread-6] o.s.c.n.e.s.EurekaServiceRegistry        : Unregistering application UNKNOWN with eureka with status DOWN
2018-12-28 13:52:16.752  WARN 20236 --- [       Thread-6] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1545985336752, current=DOWN, previous=UP]
2018-12-28 13:52:16.756  INFO 20236 --- [       Thread-6] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
2018-12-28 13:52:16.788  INFO 20236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org - registration status: 204
2018-12-28 13:52:16.789  INFO 20236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org: registering service...
2018-12-28 13:52:16.793  INFO 20236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org - registration status: 204
2018-12-28 13:52:16.793  INFO 20236 --- [       Thread-6] com.netflix.discovery.DiscoveryClient    : Unregistering ...
2018-12-28 13:52:16.799  INFO 20236 --- [       Thread-6] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org - deregister  status: 200
2018-12-28 13:52:16.805  INFO 20236 --- [       Thread-6] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient

spring-microservices-eureka-server application.yml

spring-microservices-eureka-server application.yml

---
spring:
  profiles: peer1
server:
  port: 8761
eureka:
  instance:
    hostname: peer1
  client:
    service-url:
      defaultZone: http://peer2:8762/eureka
    register-with-eureka: false
    fetch-registry: false

---
spring:
  profiles: peer2
server:
  port: 8762
eureka:
  instance:
    hostname: peer2
  client:
    service-url:
      defaultZone: http://peer1:8761/eureka
    register-with-eureka: false
    fetch-registry: false

SpringMicroservicesEurekaServerApplication.java

SpringMicroservicesEurekaServerApplication.java

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

pom.mxl

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.oreilly.cloud</groupId>
    <artifactId>spring-microservices-eureka-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-microservices-eureka-server</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.RC2</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>

spring-microservices-eureka-client

SpringMicroservicesEurekaClientApplication.java

SpringMicroservicesEurekaClientApplication.java

@SpringBootApplication
@EnableEurekaClient
public class SpringMicroservicesEurekaClientApplication {

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

参考问题: https://github.com/spring- cloud/spring-cloud-netflix/issues/2099 -这对我来说是个主要问题.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.oreilly.cloud</groupId>
    <artifactId>spring-microservices-eureka-client</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-microservices-eureka-client</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.RC2</spring-cloud.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
</project>

推荐答案

我能够通过添加网络依赖项来解决此问题

I was able to solve this issue by adding the web dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

这篇关于以编程方式使用Eureka客户端的问题-已完成DiscoveryClient的关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆