英文:
Cannot resolve org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:unknown
问题
以下是已翻译的内容:
我正在跟随一个教程学习使用 Spring Boot 创建 Eureka 服务器/客户端。当我尝试在 pom.xml 中安装 Maven 依赖时,我遇到了标题中的错误。
这是我的 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>
我该如何解决这个问题,为什么会出现这种情况?
英文:
I am following a tutorial to learn eureka server/client with spring boot
when I try to install maven dependencies in the pom.xml I get the error in the title
this is my pom.xml file:
<?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>
How can I solve this problem and why is it happening?
答案1
得分: 12
我也在跟着教程进行学习。
我使用了 Spring Boot 在 IntelliJ 2020.1 中创建了一个基本的微服务。
我向我的项目中添加了 spring-cloud-starter-netflix-eureka-client starter。
以下是添加到 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>
重新加载 Maven 的 pom.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>
解决方法:
出于某种原因,当使用 spring initializr 添加 spring-boot-starter 时,eureka discovery client 的版本没有自动添加到 pom 中。所以我手动添加了版本:
<version>2.2.5.RELEASE</version>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  <version>2.2.5.RELEASE</version>
</dependency>
然后在刷新 Maven 的 pom.xml 后,依赖项得到了识别。
英文:
I too am following a tutorial as well.
I created a basic microservice using Spring Boot in IntelliJ 2020.1
I added the spring-cloud-starter-netflix-eureka-client starter to my project.
Here is what was added to the 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>
After reloading the maven pom.xml file, I get the error that dependency is not found.
Here is the error:
> Cannot resolve org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:unknown
I am using Spring Boot 2.3.5.
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
SOLUTION :
For some reason, the version of the eureka discovery client is not added automatically to the pom when using the spring initializr to add the spring-boot-starter. So I added the version manually:
<version>2.2.5.RELEASE</version>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  <version>2.2.5.RELEASE</version>
</dependency>
Then after refreshing the maven pom.xml the dependency was recognized.
答案2
得分: 10
在 <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>
英文:
just add this code after <dependencies/> section and before <build/> section:
<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>
答案3
得分: 3
检查Spring Boot Starter版本(2.3.3)和Spring Cloud版本(2.2.5),它会导致构建失败,我建议使用Spring Initializer为您的项目创建pom/build文件。
英文:
Check the Spring boot Starter version (2.3.3) and Spring Cloud version (2.2.5), it fails your build, I recommend to use Spring Initializer to create your pom/build file for your project.
答案4
得分: 3
我通过在属性中添加Spring Cloud版本来成功解决了这个问题。
<properties>
    <java.version>11</java.version>
    <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
</properties>
英文:
I managed to solve this problem by adding spring cloud version in properties.
<properties>
    <java.version>11</java.version>
    <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
</properties>
答案5
得分: 2
修改pom.xml中的Spring Boot版本(以及Spring Cloud版本)
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/> 
    </parent>
    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
    </properties>
英文:
Change the spring boot version (and the spring cloud version) in the pom.xml
<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.1.5.RELEASE</version>
	<relativePath/> 
</parent>
<properties>
	<java.version>11</java.version>
	<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
答案6
得分: 1
我意识到 jar 文件被下载到项目文件夹中的 "Maven Dependencies" 文件夹,但 POM 错误仍然存在。
解决方案:
删除 C:\Users<user>.m2 文件夹,然后从 POM 重新加载 Maven。
英文:
I realized the jar files are downloaded into "Maven Dependencies" in the project folder but the POM error still exist.
Solution:-
Delete the C:\Users<user>.m2 folder and then reload maven from POM.
答案7
得分: 0
手动添加Eureka发现客户端的版本可以帮助解决这个问题。
我添加了版本,然后它起作用了。
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>2.2.10.RELEASE</version>
</dependency>
英文:
Adding the version of eureka discovery client manually can help to resolve the problem.
I added the version and it worked.
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>2.2.10.RELEASE</version>
</dependency>
答案8
得分: 0
请参考以下示例。在您的 pom.xml 中添加了一些您没有的内容,请忽略注释;完成后,请检查您的类型,这是区分大小写的。我的示例使用服务器。希望能解决相关问题。
    <properties>
        <!-- 使用 Java 17 -->
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <!-- 可选的(?) -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <!-- 这里的主要问题(?) -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>
信息:
文件|项目结构 -> 项目 -> SDK: SDK corretto-17
在处理过程中检查您代码示例的颜色:
//todo: 它会变成红色.. 必须有不同的颜色
@EnableEurekaServer
它应该是 红色 的。如果红色没问题.. 不要添加这行代码
//todo: 通过导入添加
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
您必须重新加载 Maven(这需要一些时间.. 对我来说需要 2 分钟)以便下载所需内容。然后将光标放在红色代码上,直到弹出式窗口显示
无法解析符号 Bla bla
然后点击 导入类。
结果应该如下所示
package com.***.eurekaserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//todo: 通过导入添加
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
//todo: 添加应用程序和服务器
@SpringBootApplication
@EnableEurekaServer
//仅为示例名称
public class EurekaServerApplication {
    //todo: 创建 main 方法
}
如果没有任何反应,您应该遵循一些建议
- 降低您的脚本版本。不是好主意
 - 降低您的 Java 版本。仍然不是好主意,我正在使用 17,而此时的新 Java 版本是 19。
 - 检查您代码中的版本。当我创建这个时,示例中的 <artifactid> 下方有一个版本,我的工作代码中未使用此行。pom.xml(父级)中的版本为
 
<spring.cloud-version>2020.0.3</spring.cloud-version>
如果您发现当前版本不起作用,请为其添加注释。
免责声明:使用 Intellij Idea。
来源:YouTube
关键词 #servicediscovery #microservices #amigoscode
为了比较,我发布了根 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.***code</groupId>
  <artifactId>***services</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>***services</name>
  <url>http://www.***services.com</url>
  <modules>
<!--这里有一些不想分享的内容-->
    <module>eureka-server</module>
  </modules>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <spring.boot.maven.plugin.version>2.5.7</spring.boot.maven.plugin.version>
    <spring.boot.dependency.version>2.5.7</spring.boot.dependency.version>
    <spring.cloud-version>2020.0.3</spring.cloud-version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring.boot.dependency.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <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>
  <dependencies>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
  </dependencies>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <version>${spring.boot.maven.plugin.version}</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
英文:
Follow below example. Added something you not have on your pom.xml please ignore the comment; when you are done, please check your type, this is case sensitive. My example using server. Hope work on related issue
    <properties>
<!-- using java 17 -->
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<!--optional(?)-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- the main problem here(?)-->
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
info:
> file|Project Structure -> project -> SDK: SDK corretto-17
during process check the color of your code example:
//todo: it goes red.. must have different color 
@EnableEurekaServer
It supposed to be red. If red is fine.. don't added this line
//todo: added by importing
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
you must reload the maven (it take times.. for me take 2 minutes) in order to download what you needed. Then put your cursor on the red code until pop-up
> cannot resolve symbol Bla bla
then click import the class.
Result you should have
package com.***.eurekaserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//todo: added by importing 
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
//todo added application and server
@SpringBootApplication
@EnableEurekaServer
//just example name
public class EurekaServerApplication {
//todo: make main
}
If nothing happen, then you should follow some suggestion
- downgrade your script. Were Bad idea
 - downgrade your java. Still bad idea, I'm using 17, while new java version on this moment are 19.
 - check the version on your code. When I make this, there is version below the <artifactid> on the example and my working code, the line not used it. the version said on the pom.xml (parent) were
 
> <spring.cloud-version>2020.0.3</spring.cloud-version>
If you find the current version not worked. Please added comment for it.
disclamer: using Intellij Idea.
source: youtube
> with keyword #servicediscovery #microservices #amigoscode
For compare purpose I'm posting root pom.xml for refences only
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.***code</groupId>
<artifactId>***services</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>***services</name>
<url>http://www.***services.com</url>
<modules>
<!--something here not wanted to share-->
<module>eureka-server</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<spring.boot.maven.plugin.version>2.5.7</spring.boot.maven.plugin.version>
<spring.boot.dependency.version  >2.5.7</spring.boot.dependency.version>
<spring.cloud-version>2020.0.3</spring.cloud-version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.dependency.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<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>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.maven.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
答案9
得分: 0
我尝试在依赖项下面添加了dependencyManagement,它起作用了
<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>
英文:
I tried adding dependencyManagement under dependencies it worked
<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>
答案10
得分: -1
在 Spring 启动时,创建项目时,还要考虑这些存储库,它们非常基础。
    <repositories>
          // 数据
    </repositories>
    <pluginRepositories>
        <pluginRepository>
          // 数据
        </pluginRepository>
        <pluginRepository>
          // 数据
        </pluginRepository>
    </pluginRepositories>
英文:
At Spring Start, when creating the project,
also take the repositories, these guys are fundamental.
<repositories>
// DATA
</repositories>
<pluginRepositories>
<pluginRepository>
// DATA
</pluginRepository>
<pluginRepository>
// DATA
</pluginRepository>
</pluginRepositories>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论