如何下载阅读Spring源码-全过程详解

news2024/11/30 6:43:26

这篇文章记录了下载spring源码和在IDEA中打开运行的全过程,并且记录了过程中遇到的问题和解决方案,适合需要学习spring源码的同学阅读。

1.spring源码下载地址

通过Git下载spring-framework项目源码:

git clone https://github.com/spring-projects/spring-framework.git

2.使用IDEA构建spring-framework源码

笔者用的IDEA版本是社区版IDEA:IntelliJ IDEA 2020.34(Community Edition),用IDEA打开源码后,IDEA会自动加载Gradle项目依赖。

然后这里就遇到了第一个问题:

2.1 SSL证书验证不通过(无该问题可跳过)

SunCertPathBuilderException: unable to find valid certification path to requested target - Mkyong.com

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building_迷茫期。。。的博客-CSDN博客

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:439)
	at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:306)
	at sun.security.validator.Validator.validate(Validator.java:271)
	at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:312)
	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:221)
	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:128)
	at sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:630)
	... 126 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
	at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
	at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
	at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:434)

> Task :buildSrc:compileJava FAILED
1 actionable task: 1 executed

A build scan was not published as you have not authenticated with server 'ge.spring.io'.
For more information, please see https://gradle.com/help/gradle-authenticating-with-gradle-enterprise.
The remote build cache was disabled during the build due to errors.

2.1.1 新建InstallCert .java文件

/*
 - Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
 -  - Redistribution and use in source and binary forms, with or without
 - modification, are permitted provided that the following conditions
 - are met:
 -  -   - Redistributions of source code must retain the above copyright
 -     notice, this list of conditions and the following disclaimer.
 -  -   - Redistributions in binary form must reproduce the above copyright
 -     notice, this list of conditions and the following disclaimer in the
 -     documentation and/or other materials provided with the distribution.
 -  -   - Neither the name of Sun Microsystems nor the names of its
 -     contributors may be used to endorse or promote products derived
 -     from this software without specific prior written permission.
 -  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 - IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 - THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 - PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
import java.io.*;
import java.net.URL;
 
import java.security.*;
import java.security.cert.*;
 
import javax.net.ssl.*;
 
public class InstallCert {
 
    public static void main(String[] args) throws Exception {
    String host;
    int port;
    char[] passphrase;
    if ((args.length == 1) || (args.length == 2)) {
        String[] c = args[0].split(":");
        host = c[0];
        port = (c.length == 1) ? 443 : Integer.parseInt(c[1]);
        String p = (args.length == 1) ? "changeit" : args[1];
        passphrase = p.toCharArray();
    } else {
        System.out.println("Usage: java InstallCert <host>[:port] [passphrase]");
        return;
    }
 
    File file = new File("jssecacerts");
    if (file.isFile() == false) {
        char SEP = File.separatorChar;
        File dir = new File(System.getProperty("java.home") + SEP
            + "lib" + SEP + "security");
        file = new File(dir, "jssecacerts");
        if (file.isFile() == false) {
        file = new File(dir, "cacerts");
        }
    }
    System.out.println("Loading KeyStore " + file + "...");
    InputStream in = new FileInputStream(file);
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    ks.load(in, passphrase);
    in.close();
 
    SSLContext context = SSLContext.getInstance("TLS");
    TrustManagerFactory tmf =
        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(ks);
    X509TrustManager defaultTrustManager = (X509TrustManager)tmf.getTrustManagers()[0];
    SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);
    context.init(null, new TrustManager[] {tm}, null);
    SSLSocketFactory factory = context.getSocketFactory();
 
    System.out.println("Opening connection to " + host + ":" + port + "...");
    SSLSocket socket = (SSLSocket)factory.createSocket(host, port);
    socket.setSoTimeout(10000);
    try {
        System.out.println("Starting SSL handshake...");
        socket.startHandshake();
        socket.close();
        System.out.println();
        System.out.println("No errors, certificate is already trusted");
    } catch (SSLException e) {
        System.out.println();
        e.printStackTrace(System.out);
    }
 
    X509Certificate[] chain = tm.chain;
    if (chain == null) {
        System.out.println("Could not obtain server certificate chain");
        return;
    }
 
    BufferedReader reader =
        new BufferedReader(new InputStreamReader(System.in));
 
    System.out.println();
    System.out.println("Server sent " + chain.length + " certificate(s):");
    System.out.println();
    MessageDigest sha1 = MessageDigest.getInstance("SHA1");
    MessageDigest md5 = MessageDigest.getInstance("MD5");
    for (int i = 0; i < chain.length; i++) {
        X509Certificate cert = chain[i];
        System.out.println
            (" " + (i + 1) + " Subject " + cert.getSubjectDN());
        System.out.println("   Issuer  " + cert.getIssuerDN());
        sha1.update(cert.getEncoded());
        System.out.println("   sha1    " + toHexString(sha1.digest()));
        md5.update(cert.getEncoded());
        System.out.println("   md5     " + toHexString(md5.digest()));
        System.out.println();
    }
 
    System.out.println("Enter certificate to add to trusted keystore or 'q' to quit: [1]");
    String line = reader.readLine().trim();
    int k;
    try {
        k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1;
    } catch (NumberFormatException e) {
        System.out.println("KeyStore not changed");
        return;
    }
 
    X509Certificate cert = chain[k];
    String alias = host + "-" + (k + 1);
    ks.setCertificateEntry(alias, cert);
 
    OutputStream out = new FileOutputStream("jssecacerts");
    ks.store(out, passphrase);
    out.close();
 
    System.out.println();
    System.out.println(cert);
    System.out.println();
    System.out.println
        ("Added certificate to keystore 'jssecacerts' using alias '"
        + alias + "'");
    }
 
    private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();
 
    private static String toHexString(byte[] bytes) {
    StringBuilder sb = new StringBuilder(bytes.length * 3);
    for (int b : bytes) {
        b &= 0xff;
        sb.append(HEXDIGITS[b >> 4]);
        sb.append(HEXDIGITS[b & 15]);
        sb.append(' ');
    }
    return sb.toString();
    }
 
    private static class SavingTrustManager implements X509TrustManager {
 
    private final X509TrustManager tm;
    private X509Certificate[] chain;
 
    SavingTrustManager(X509TrustManager tm) {
        this.tm = tm;
    }
 
    public X509Certificate[] getAcceptedIssuers() {
        throw new UnsupportedOperationException();
    }
 
    public void checkClientTrusted(X509Certificate[] chain, String authType)
        throws CertificateException {
        throw new UnsupportedOperationException();
    }
 
    public void checkServerTrusted(X509Certificate[] chain, String authType)
        throws CertificateException {
        this.chain = chain;
        tm.checkServerTrusted(chain, authType);
    }
    }
 
}

2.1.2 编译InstallCert .java

javac InstallCert.java

2.1.3 运行InstallCert,生成jssecacerts文件

--输入命令(域名换成自己idea访问报错的域名或者ip)
java InstallCert ge.spring.io:443

命令执行后,会要求输入数字1,生成证书文件

 出现如下信息就代表安装成功

 2.1.4 将同目录下生成的jssecacerts文件添加到$JAVA_HOME/jre/lib/security

2.1.5 重启IDEA(注意重启,不然可能不会生效)

这个问题这样就解决啦!

不过又出现了新的问题😂

2.2 KotlinConventions类编译失败

> Task :buildSrc:compileJava FAILED
D:\Users\project\spring-framework\buildSrc\src\main\java\org\springframework\build\KotlinConventions.java:44: ����: �Ҳ�������
		freeCompilerArgs.addAll(List.of("-Xsuppress-version-warnings", "-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn"));
		                            ^
  ����:   ���� of(java.lang.String,java.lang.String,java.lang.String)
  λ��: �ӿ� java.util.List
1 ������

2.2.1 问题原因

https://www.cnblogs.com/haoxianrui/p/16975079.html

笔者本地使用了jdk8,而spring源码现在已经使用了jdk 17,所以我本地的jdk不适用于spring-framework,需要重新下载jdk17

2.2.2 下载使用jdk 17

Java JDK下载与安装教程

安装之后,在Gradle设置里,使用我们下载的jdk17

问题解决

2.3 无法获取到依赖的jar包

Could not download reactor-netty5-http-2.0.0-M3.jar (io.projectreactor.netty:reactor-netty5-http:2.0.0-M3)
Could not get resource 'https://repo.spring.io/milestone/io/projectreactor/netty/reactor-netty5-http/2.0.0-M3/reactor-netty5-http-2.0.0-M3.jar'.
Could not GET 'https://jfrog-prod-use1-shared-virginia-main.s3.amazonaws.com/aol-springsource/filestore/86/865933d3682c52611968163a012ff66b9872b71a?X-Artifactory-username=anonymous&X-Artifactory-repositoryKey=libs-milestone-local&X-Artifactory-artifactPath=io%2Fprojectreactor%2Fnetty%2Freactor-netty5-http%2F2.0.0-M3%2Freactor-netty5-http-2.0.0-M3.jar&X-Artifactory-projectKey=default&x-jf-traceId=4d07ec9a25940234&response-content-disposition=attachment%3Bfilename%3D%22reactor-netty5-http-2.0.0-M3.jar%22&response-content-type=application%2Fjava-archive&X-Amz-Security-Token=FwoGZXIvYXdzECIaDHVyEGk3w71HFKwaYiKlBFzfmjii%2Fj83al2YQhVAEsu3fvEqpDokpVyh7MRIlErCfyQgqa6VeIO5vFtEZjFWqd7hdrFH2xJHqfct1IFfzWuadfgyUIATPyd1fiAVGuTtqhuz3jn4rEPVgOkGZPYaOp9YGNXP7T5UB%2BYc8aftvD8ORRKbsNkaoB4EbWmpPRtGcSGnnQUPLpccRlDqpoIUKSyiEfwrpoeuWtaJp4Y%2FYQBG6UEpq9n2NYddnTaieE5t%2ByaipzZ3RRbJPteBcuud%2FMVxeWy%2BMR7mrezhQe6TRy7Au4AX7Dm1%2FFiboXC%2BLu06o82jTMLWHBx8uxXvrzhMJ6Rk0SlFEB2YhkHLy%2BJfSrRlrCfg3t0buTjeGosZ8W59yJXrHjKIQnTx04J2KlKUUHi6i7b%2BnyNlEwCEs61BnrWZsrd89QvCOgQ7I3yA4zFUii2ugr2gj0BGgvYTKjYO6PlwkDiYu2c5Tw8kUEmDLyOxqBaVH4tkrPBY0uu29ggvrBPTOgP6puhL45TsTW3MO6V9sHFQjJrIJ9rAuAc3tHK0CoN7aQ3MxCoezjvrUN6KB%2BXVxT7ZEia%2FP%2BNec%2BLL9b0CRM7tLnJ9ly6w59y5KrnmeeAQ6%2FjWgd6lmJqS2gknMXqvGTkIHu95RTHO7dSu2yaaeqqBGnQUc%2FmQG4d5tTQdvUOgAY2nVEzTe%2BVZhnUiVFMg%2F%2BmudQWCPKZxtAnNtxhgQelur%2FEe9eFd9oNta1DOCRlKVSj7s86fBjIrtSsd354CSxF%2FP23mYpHUuWchiZXrJzk6gk%2FsmBFsOA%2FfjApBVe1mZ3RB9Q%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230220T160636Z&X-Amz-SignedHeaders=host&X-Amz-Expires=60&X-Amz-Credential=ASIA6RUGCBMHDIGDGT7Q%2F20230220%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=eff0beab0b224964c11606d240a9ec4ce6aa4cbe60db666d5157c6dfafc1811d'.
Connection reset

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

这个要排除下是网络问题还是代理问题

先使用ping命令看下网络是不是通的

这里看到,ping命令请求超时,但是直接浏览器访问,是没问题的,再看看是不是代理问题

打开IDEA设置setting,找到HTTP Proxy,选择Auto-detect proxy setting(自动发现代理设置),然后应用

 重新刷新Gradle依赖,发现开始下载依赖包了,最后BUILD SUCCESSFUL,大功告成😁

接下来就可以愉快的阅读源码啦!

后续我将会边学习边写源码阅读笔记,并同步到博客,欢迎大家多互相交流!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/363635.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Document-Level event Extraction via human-like reading process 论文解读

Document-Level event Extraction via human-like reading process 论文&#xff1a;2202.03092v1.pdf (arxiv.org) 代码&#xff1a;无 期刊/会议&#xff1a;ICASSP 2022 摘要 文档级事件抽取(DEE)特别困难&#xff0c;因为它提出了两个挑战:论元分散和多事件。第一个挑战…

TPM 2.0实例探索2 —— LUKS磁盘加密(1)

本文大部分内容取自&#xff1a; LUKS磁盘格式_小写的毛毛的博客-CSDN博客_luks 如何破解LUKS加密 一、LUKS介绍 1. 什么是LUKS LUKS是“Linux Unified Key Setup”的简写&#xff0c;是 Linux 硬盘加密的标准。LUKS通过提供标准的磁盘格式&#xff0c;不仅可以促进发行版之…

短链或H5唤醒(跳转)APP应用

唤醒APP(两种方法) 一.短链唤醒(跳转)app ⭐ 短链跳转到APP&#xff0c;当如果用户手机不存在APP(某个应用)将会进入到官网页面。 app links实现 在android studio菜单栏Tools->App Links Ass点击,效果图如下 2.配置如下 点击ok,生成如下效果图 3.完成第二步后,会自动…

深度解读 | 数据资产管理面临诸多挑战,做好这5个措施是关键

日前&#xff0c;大数据技术标准推进委员会&#xff08;中国通信标准化协会下&#xff08;CCSA&#xff09;的专业技术委员会&#xff0c;简称TC601&#xff09;发布《数据资产管理实践白皮书》&#xff08;6.0 版&#xff09;&#xff08;以下简称&#xff1a;报告&#xff09…

网友说socket通信讲的不彻底,原来这才是Socket

关于对 Socket 的认识&#xff0c;大致分为下面几个主题&#xff0c;Socket 是什么&#xff0c;Socket 是如何创建的&#xff0c;Socket 是如何连接并收发数据的&#xff0c;Socket 套接字的删除等。 Socket 是什么以及创建过程 一个数据包经由应用程序产生&#xff0c;进入到…

linux下安装mongoDB

一、下载mongoDB包 下载地址&#xff1a; https://www.mongodb.com/try/download/community 个人建议&#xff1a;如果是学习阶段&#xff0c;使用5以下版本更好些。 二、安装及配置 1、安装 # 1、解压 $ tar -zxvf mongodb-linux-x86_64-rhel70-4.4.19-rc1.tgz# 2、迁移目…

【二叉树】

1&#xff0c;利用类来构建结点&#xff0c;利用函数递归来构建树2&#xff0c;因为左子树的结点编号是父节点的2倍&#xff0c;右子树的结点编号是父节点的2倍1&#xff0c;所以可以用数组模拟建树的过程构建二叉树第一种构建方式class treenode():#二叉树节点def __init__(se…

【西安】Python-GEE遥感云大数据分析、管理与可视化技术及多领域案例实践应用

目录 第一章 理论基础 第二章 开发环境搭建 第三章 遥感大数据处理 基础 第四章 典型案例操作实践 第五章 输入输出及数据 资产高效管理 第六章 云端数据论文出版级可视化 ​随着航空、航天、近地空间等多个遥感平台的不断发展&#xff0c;近年来遥感技术突飞猛进。由此&…

使用代码生成器生成代码

一、新建数据源配置 因考虑到多数据源问题&#xff0c;代码生成器作为一个通用的模块&#xff0c;后续可能会为其他工程生成代码&#xff0c;所以&#xff0c;这里不直接读取系统工程配置的数据源&#xff0c;而是让用户自己维护。 新建数据源 参数说明 数据源名称&#xff1…

CIMCAI intellgent ship product applied by world top3 shipcompany

CIMCAI智慧船公司集装箱管理产品ceaspectusS™全球规模应用全球前三大船公司认可验箱标准应用落地全球港航人工智能AI独角兽 CIMCAI中集飞瞳CIMCAI Intellgent shipping product ceaspectusS ™which applied by the worlds top three shipping companiesGlobal port and shipp…

关于ch340驱动安装

这是一个悲伤的故事&#xff0c;搞了一上午&#xff0c;最后的解决办法是我找到了开发板的原装数据线&#xff0c;一换上去&#xff0c;板卡上电后&#xff0c;点击安装&#xff0c;就安装驱动成功了。。。。。把我走过的弯路记录在下面&#xff0c;链接里的办法是能解决阶段问…

【Go】使用Go语言打造定时提醒小工具,从基础到优化全方位探索

文章目录一、引言1.目的和背景2.选择GO语言的原因二、GO语言中的时间和定时器1.时间相关的包和函数2.定时器相关的包和函数三、使用GO语言实现功能四、代码改进1.time.AfterFunc()2.sync.WaitGroup3.接收参数五、总结一、引言 1.目的和背景 本文为征文活动“CSDN 征文活动&am…

(二十二)、实现评论功能(2)【uniapp+uinicloud多用户社区博客实战项目(完整开发文档-从零到完整项目)】

1&#xff0c;渲染评论列表 1.1&#xff0c;在detail页面中定义评论列表数组和getcomment方法&#xff1a; commentList: [],getcomment方法&#xff1a; //获取评论列表async getComment() {let commentTemp db.collection("quanzi_comment").where(article_id …

浏览器跨域问题

跨域问题什么是跨域问题如何解决跨域问题JSONPCORS方式解决跨域使用 Nginx 反向代理使用 WebSocket跨源请求是否能携带Cookie什么是跨域问题 跨域问题指的是不同站点之间&#xff0c;使用 ajax 无法相互调用的问题。跨域问题本质是浏览器的一种保护机制&#xff0c;它的初衷是为…

【离线数仓-3-数仓建模方法理论汇总】

离线数仓-3-数仓建模方法理论汇总离线数仓-3-数仓建模方法理论汇总1.数仓概述2.数据仓库核心架构&#xff08;Hive&#xff09;3.数据仓库建模概述4.数据仓库建模方法论1.ER&#xff08;Entity Relationship&#xff09;模型2.维度模型1.维度建模理论-事实表1. 事实表概述2.事实…

RabbitMQ学习(十):发布确认高级

一、概述在生产环境中由于一些不明原因&#xff0c;导致 RabbitMQ 重启&#xff0c;在 RabbitMQ 重启期间生产者消息投递失败导致消息丢失&#xff0c;需要手动处理和恢复。在这样比较极端的情况&#xff0c;当RabbitMQ 集群不可用的时候&#xff0c;无法投递的消息该如何处理呢…

面试题:HashMap为什么是线程不安全的?解决办法是什么?

在JDK1.7中容易造成死循环和数据丢失&#xff0c;造成的原因如下图假设某个时刻t1,t2都访问到了链表&#xff0c;t1,t2的下一个节点都是b,如图此时内存耗尽&#xff0c;线程t2线程进入等待状态&#xff0c;假设此时刚好达到临界点需要扩容&#xff0c;t1进行扩容&#xff0c;并…

【20230210】二叉树小结

二叉树的种类二叉树的主要形式&#xff1a;满二叉树和完全二叉树。满二叉树深度为k&#xff0c;有2^k-1个节点的二叉树完全二叉树除了最底层节点可能没填满外&#xff0c;其余每层节点数都达到最大值&#xff0c;并且最下面一层的节点都集中在该层最左边的若干位置。二叉搜索树…

浅谈毫米波技术与应用

浅谈毫米波之技术篇2020年10月GSMA发布的《5G毫米波技术白皮书》预计&#xff0c;在2022年北京冬奥会上&#xff0c;5G毫米波有望大放异彩&#xff0c;为观众、媒体转播者、赛事组织和参与者等提供优质的观赛体验、完备的服务保障&#xff0c;将可提供全景VR、新型信息交互、智…

SCADA-1-组态前期需求调研篇

近期有朋友找到我&#xff0c;说scada组态系统开源的很少&#xff0c;不少开发者借此售卖这种软件&#xff0c;我回了句&#xff1a;这有什么难的&#xff0c;不就是拖拖拽拽&#xff0c;再绑定上数据源&#xff0c;实现动态效果嘛。。。&#xff08;先装了个X&#xff09;一、…