执行器依赖性无法解决

Actuator dependency could not be resolved

我试图在我的项目中包含 spring 执行器,但是当我添加依赖项并 运行 maven clean install 我收到错误消息:

[ERROR] Failed to execute goal on project demo: Could not resolve dependencies for project com.example:demo:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.springframework.boot:spring-boot-starter-actuator:jar:2.2.4.RELEASE: Failed to read artifact descriptor for org.springframework.boot:spring-boot-starter-actuator:jar:2.2.4.RELEASE: Could not transfer artifact org.springframework.boot:spring-boot-starter-actuator:pom:2.2.4.RELEASE from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org: Unknown host repo.maven.apache.org -> [Help 1]

查看下面我的 pom 文件:

<?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.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</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>

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

    </dependencies>

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

</project>

如果我删除执行器依赖项,项目将成功构建。

我试图找到问题所在,似乎与我使用的 spring-boot-starter-parent 的版本有冲突,但我找不到解决方案。

这个问题其实和spring或者spring开机没有关系: 显然是 maven 中央存储库中的执行器 exists。所以这纯粹是一个专家问题。

Unknown host repo.maven.apache.org -> [Help 1]

此异常表示maven 无法联系中央存储库并将执行器jar 下载到本地存储库。 所以我会检查本地存储库,它可能是空的或包含一些损坏的工件。

  1. 确保您可以访问互联网
  2. 从 m2 存储库中删除损坏的工件
  3. 重新尝试运行mvn package

我用IDEA遇到了同样的问题,我的原因是我的Maven在离线模式下工作,所以我通过以下两步解决了它:

  1. go to IDEA settings and click Maven.
  2. uncheck the work offline checkbox.