无法解析 org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:unknown

6 java spring-boot netflix-eureka

当我尝试pom.xml在标题中安装 maven 依赖项时,我正在按照教程学习带有 Spring Boot 的 eureka 服务器/客户端

这是我的 pom.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://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.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.nlimits</groupId>
    <artifactId>movie_info_service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>movie_info_service</name>
    <description>Movie Info Service</description>

    <properties>
        <java.version>11</java.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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

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

</project>
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题,为什么会发生?

Ami*_*mir 15

我也在遵循教程。

我在IntelliJ 2020.1中使用 Spring Boot 创建了一个基本的微服务

我将spring-cloud-starter-netflix-eureka-client启动器添加到我的项目中。

以下是添加到的内容pom.xml

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

 <dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-dependencies</artifactId>
  <version>Hoxton.SR8</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

重新加载mavenpom.xml文件后,出现找不到依赖项的错误。

这是错误:

无法解析 org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:unknown

我正在使用 Spring Boot 2.3.5。

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
Run Code Online (Sandbox Code Playgroud)

解决方案 :

由于某些原因,在使用springinitializr添加spring-boot-starter时,eureka发现客户端的版本没有自动添加到pom中。所以我手动添加了版本:

<version>2.2.5.RELEASE</version>
Run Code Online (Sandbox Code Playgroud)
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  <version>2.2.5.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

然后刷新 maven pom.xml 后,依赖关系被识别。


小智 11

<dependencies/>只需在部分之后和部分之前添加以下代码<build/>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-parent</artifactId>
            <version>Greenwich.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)