IDEA 新建spring框架的项目时报错:下载maven依赖包失败(Failed to download xxx.jar)

IDEA 新建spring框架的项目时报错:下载maven依赖包失败(Failed to download xxx.jar)


报错现象:

今天在学习Nacos的时候,打算建个demo项目来玩玩;结果新建一个spring框架的时候就报错了,如下:

Failed to download 'https://repo1.maven.org/maven2/org/springframework/spring-aop/5.2.3.RELEASE/spring-aop-5.2.3.RELEASE.jar':等等...的报错信息.

意思很明确就是下载依赖包失败!


解决思路:

通过查看报错信息,就可以知道,依赖包下载的地址是: https://repo1.maven.org/maven2/org/springframework/spring-aop/5.2.3.RELEASE/xxxxxx.jar

对IDEA比较熟悉的人,应该都知道了,这是IDEA默认的依赖包远程下载地址,也就是maven仓库.

但是呢,这是国外的网址,因此一般情况下,获取这些国外的资源时,下载速度超慢,导致丢包严重.

因此很简单,就是修改下载地址就好了:通过给IDEA配置国内镜像(如:阿里云镜像)就能大大提高下载速度了.


具体操作:

1.找到settings.xml文件

找到自己安装的maven目录下的conf,就能看见settings.xml文件了,如图:

可以用 记事本 或 notepad++  等文本编辑工具打开该文档,也可以直接拖入 IDEA 中打开该文件.

2.添加镜像配置

找到<mirrors>  </mirrors>标签,该标签的原内容如下:

<!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->

<mirrors>

现在将整个<mirrors>  </mirrors>标签的内容,替换为下面的内容即可:
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
     <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>    
    
    <mirror>
      <id>repo2</id>
      <mirrorOf>central</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://repo2.maven.org/maven2/</url>
    </mirror>
    
    <mirror>
        <id>uk</id>
        <mirrorOf>central</mirrorOf>
        <name>Human Readable Name for this Mirror.</name>
        <url>http://uk.maven.org/maven2/</url>
    </mirror>
 
    <mirror>
        <id>CN</id>
        <name>OSChina Central</name>
        <url>http://maven.oschina.net/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
 
    <mirror>
        <id>nexus</id>
        <name>internal nexus repository</name>
        <!-- <url>http://192.168.1.100:8081/nexus/content/groups/public/</url>-->
        <url>http://repo.maven.apache.org/maven2</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
  
  </mirrors>

第一个<mirror></mirror>标签就是阿里云镜像:,如下:

<mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>    

一般来说添加这一个镜像就可以了,后面的是备用镜像地址,可以根据喜好选择是否添加.

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值