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

pdtvr36n  于 2023-01-29  发布在  Java
关注(0)|答案(3)|浏览(201)

我创建了两个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链接是:here您能否帮助我查找错误?

w6lpcovy

w6lpcovy1#

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

72qzrwbm2#

在www.example.com文件中添加此行application.properties
Eureka .客户端.已启用=真
然后尝试重新部署相同的设备。

ubbxdtey

ubbxdtey3#

尝试添加这两个依赖项后运行,希望它能工作。

<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>

相关问题