官网给的maven是这样的,
<repository>
<id>repository.spring.milestone</id>
<name>Spring Milestone Repository</name>
<url>https://repo.spring.io/milestone</url>
</repository>
...
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.0.0-M2</version>
</dependency>
弄到Idea后报错,
unable to find valid certification path to requested target
以及未解析的依赖项: 'org.springframework:spring-context:jar:6.0.0-M2'
重新加载项目也没有用,实际还是一样的错
org.springframework:spring-expression:jar:6.0.0-M2 failed to transfer from https://repo.spring.io/milestone during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of repository.spring.milestone has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework:spring-expression:jar:6.0.0-M2 from/to repository.spring.milestone (https://repo.spring.io/milestone): PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
看起来像是证书的问题,查了很多别人的解决方法,一点用都没有!
后来才摸索出来:
repository中的<url>https://repo.spring.io/milestone</url>其实是会重定向的,这个才是关键,因为放到地址栏后可以发现,真正的地址是https://repo.spring.io/ui/native/milestone
替换了url后再试就成功了。
2023/02/19补充:
用以上方式处理仍会有其他的问题,终结解决方法是修改镜像url, 以下是用的阿里的镜像地址,修改maven的setting文件。
<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>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
</mirrors>