Springboot 中 Could not transfer artifact xxxxxx failed: connect timed out 问题解决

有时构建工程,会出现下面这种格式的报错

Could not transfer artifact com.alibaba.cloud:aliyun-spring-boot-dependencies:pom:1.0.0 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.76.215] failed: connect timed out

报错图片信息

步骤:单独提取国内镜像加速配置

1. Maven 仓库镜像加速配置

将以下部分提取出来,添加到你的 settings.xml 文件中。settings.xml 文件通常位于 Maven 的配置目录(如 C:\Users\<你的用户名>\.m2\...\settings.xml)下:

<mirrors>
    <mirror>
        <id>aliyun-central</id>
        <mirrorOf>central</mirrorOf>
        <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
    <mirror>
        <id>aliyun-spring</id>
        <mirrorOf>spring</mirrorOf>
        <url>https://maven.aliyun.com/repository/spring</url>
    </mirror>
</mirrors>
2. 添加国内镜像的仓库配置

在项目下 pom.xml 文件中单独指定 Maven 仓库(如阿里云仓库):
在这里插入图片描述

复制下来粘到这里

在这里插入图片描述

代码如下
<repositories>
    <repository>
        <id>aliyun-central</id>
        <url>https://maven.aliyun.com/repository/central</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>aliyun-spring</id>
        <url>https://maven.aliyun.com/repository/spring</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>aliyun-central</id>
        <url>https://maven.aliyun.com/repository/central</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

这样做能够确保你的项目无论是在国内还是在其他网络环境下,都能有效地进行依赖下载和构建。

结果如图

在这里插入图片描述

至于gradle,不急,还在学。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值