在eureka服务器中添加eureka客户端出错,客户端模块无法启动

问题描述 投票:0回答:3

我创建了两个spring-cloud模块,一个是eureka-server,运行良好,另一个是eureka client,当我启动它时,出现错误。

2018-07-25 18:06:21.717 ERROR 15352 --- [           main] o.s.c.n.e.s.EurekaRegistration           : error getting CloudEurekaClient

 org.springframework.beans.factory.BeanCreationException: Error 
 creating bean with name 'scopedTarget.eurekaClient' defined in class 
 path resource [ . 
 org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$Ref .    reshableEurekaClientConfiguration.class]: Bean instantiation via 
 factory method failed; nested exception is 
 org.springframework.beans.BeanInstantiationException: Failed to 
 instantiate [com.netflix.discovery.EurekaClient]: Factory method 
 'eurekaClient' threw exception; nested exception is 
 java.lang.RuntimeException: Failed to initialize DiscoveryClient!

github 链接是:这里 你能帮我找出错误吗?

java spring spring-cloud
3个回答
0
投票

在客户端的 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-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>

0
投票

在 application.properties 文件中添加此行

eureka.client.enabled=true

然后尝试重新部署相同的内容。


0
投票

添加这两个依赖后尝试运行希望它能起作用。

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
<dependency>
  <groupId>com.netflix.eureka</groupId>
  <artifactId>eureka-core</artifactId>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.