配置了maven的国内镜像后,问题:(https://repo.maven.apache.org/maven2): Not authorized , ReasonPhrase:Authorizatio

一.问题:

最近学习springboot,从网上导入工程后,都出现maven无法下载相关资源的问题。

二.解决思路如下:

1.怀疑是网络限制的原因,故在网上找了相关的解决方案,使用了阿里的云仓库,在maven的settings.xml文件的Mirrors中添加了如下内容:

<mirrors>
	 
	  <!-- 阿里云仓库 -->
        <mirror>
            <id>alimaven</id>
           <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>https://maven.aliyun.com/nexus/content/repositories/central/</url>
         </mirror>
     
        <!-- 中央仓库1 -->
        <mirror>
            <id>repo1</id>
             <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo1.maven.org/maven2/</url>
         </mirror>
     
         <!-- 中央仓库2 -->
         <mirror>
             <id>repo2</id>
             <mirrorOf>central</mirrorOf>
             <name>Human Readable Name for this Mirror.</name>
             <url>http://repo2.maven.org/maven2/</url>
         </mirror>

  </mirrors>

2.添加完成后,发现部分资源 可以下载了,但仍然有许多资源无法下载,后来参考了https://blog.sonatype.com/using-nexus-3-as-your-repository-part-1-maven-artifacts,发现pom.xml都是继承自super pom,
super pom中的有如下内容:

<repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Central Repository</name>
      <url>http://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
    </pluginRepository>
  </pluginRepositories>

故当maven下载资源时,会优先使用http://repo.maven.apache.org/maven2去下载。

最终解决方案是在自定义的pom.xml中加入如下内容:

<repositories>
    <repository>
        <id>central</id>
        <url>http://host:port/content/groups/public</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>central</id>
        <url>http://host:port/content/groups/public</url>
    </pluginRepository>
</pluginRepositories>

 

  • 17
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值