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>
一般来说添加这一个镜像就可以了,后面的是备用镜像地址,可以根据喜好选择是否添加.