前言

本文记录了 Spring 源码环境的搭建方式,以及踩过的那些坑!​当前版本:5.3.2-SNAPSHOT。

环境准备

  1. Git
  2. JDK
    1. master 分支需要 JDK 11
    2. 5.2.x 分支, JDK8 即可
  3. Gradle 6.5.1
  4. IDEA 最新 (2020.2.3)

Spring 源码仓库地址:https://github.com/spring-projects/spring-framework

下载源码

  1. clone 源码
git clone  https://github.com/spring-projects/spring-framework.git
  1. 使用 IDEA 打开

    1. 等待 IDEA 加载完成即可。

注: 也可以指定 clone 的分支

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

或者先 fork 到自己的仓库,然后再 clone。

这里我是 fork 到我的仓库,然后再 clone 的。

当前 master 分支代表的版本为 5.3.2-SNAPSHOT。

执行测试

  • 在项目右键创建 module

  • 选择 Gradle Java

  • 创建 module

  • 在 build.gradle 中添加配置
compile(project(":spring-context"))

  • 创建测试类并测试

其中 UserComponent 添加了 @Component 注解, 程序正常执行则一切 OK。可以开始愉快的调试代码了。

问题总结

编译失败

有小伙伴直接下载 zip 包,可能遇到以下问题:(非常不建议直接下载 zip 包构建,想知道原因可以继续看,最后我也没有构建成功,而是直接通过 clone 构建的。)

  1. 报错如下:
fatal: not a git repository (or any of the parent directories): .git

BUILD SUCCESSFUL in 14s
Build scan background action failed.
org.gradle.process.internal.ExecException: Process 'command 'git'' finished with non-zero exit value 128
... 其他省略

看意思是没有 git 配置,那就添加上吧!

  1. 这时候想着添加 git

VCS -> Enable Version Control Integration... -> 右上角 Reload All Gradle Projects

依然报错

fatal: Needed a single revision

  1. 查询问题

issues 地址:https://github.com/spring-projects/spring-framework/issues/24467

建议使用

$ git clone git@github.com:spring-projects/spring-framework.git

意思就是 zip 发行版主要是用来共享源代码,但不一定用于构建它。

  1. 最后我选择了使用 clone 的方式,直接 clone 下来,然后 build 通过。

缺少 cglib 和 objenesis 包

Kotlin: warnings found and -Weeror specified

没有 spring-cglib-repackspring-objenesis-repack

执行这两个即可。

找不到包 jdk.jfr

import jdk.jfr.Category;
import jdk.jfr.Description;
import jdk.jfr.Event;
import jdk.jfr.Label;

JDK 升级为 11。因为我本地使用的是 JDK8,发现报错,jfr 包需要升级 JDK 11 才有。

如果不生效,可以通过:

IDEA -> File -> Project Structure -> Project 检查下是否修改为 JDK 11

快捷键:⌘ + ;

相关资料

  1. Spring 仓库:https://github.com/spring-projects/spring-framework
  2. Spring 构建文档:https://github.com/spring-projects/spring-framework/wiki/Build-from-Source

历史文章

Spring 源码阅读环境的搭建的更多相关文章

  1. Sping学习笔记(一)----Spring源码阅读环境的搭建

    idea搭建spring源码阅读环境 安装gradle Github下载Spring源码 新建学习spring源码的项目 idea搭建spring源码阅读环境 安装gradle 在官网中下载gradl ...

  2. 搭建 Spring 源码阅读环境

    前言 有一个Spring源码阅读环境是学习Spring的基础.笔者借鉴了网上很多搭建环境的方法,也尝试了很多,接下来总结两种个人认为比较简便实用的方法.读者可根据自己的需要自行选择. 方法一:搭建基础 ...

  3. Spring源码阅读环境搭建

    目录 安装gradle 导入Spring源码 创建测试模块my-test 其他问题 spring-aspects模块构建时报错 本文思维导图 本文将粗略的搭建一个Spring源码的阅读环境,为后面的源 ...

  4. Spring源码分析_01_ idea搭建spring源码阅读环境

    二.参考资料 1.Intellij Idea如何导入spring源码

  5. idea构建spring源码阅读环境

    注:由于文章不是一次性完成,下文中的test1目录和test目录应为同一个目录. (一)安装git和Gradle Spring项目托管在github之上,基于Gradle来构建项目.所以要想搭建Spr ...

  6. spark2.1源码分析1:Win10下IDEA源码阅读环境的搭建

    环境:win10.IDEA2016.3.maven3.3.9.git.scala 2.11.8.java1.8.0_101.sbt0.13.12 下载: #git bash中执行: git clone ...

  7. Spring源码阅读笔记01:源码阅读环境准备

    1. 写在前面 对于做Java开发的同学来说,Spring就像是一条绕不过去的路,但是大多数也只是停留在对Spring的简单使用层面上,对于其背后的原理所知不多也不愿深究,关于这个问题,我在平时的生活 ...

  8. Spring5源码阅读环境搭建-gradle构建编译

      前沿:Spring系列生态十分丰富,涉及到各个方面.但是作为Spring生态的核心基础Spring,是最重要的环节,需要理解Spring的设计原理,我们需要解读源码.   在构建Spring源码阅 ...

  9. Spring源码阅读笔记02:IOC基本概念

    上篇文章中我们介绍了准备Spring源码阅读环境的两种姿势,接下来,我们就要开始探寻这个著名框架背后的原理.Spring提供的最基本最底层的功能是bean容器,这其实是对IoC思想的应用,在学习Spr ...

随机推荐

  1. 测试可变字符序列stringBuilder

    测试可变字符序列 stringBuilder(线程不安全,效率高,一般用),stringBuffer(线程安全,效率低)stringBuilder,stringBuffer和string的区别前者可变 ...

  2. Java基础知识(三)

    一.hashCode 与 equals (重要) 面试官可能会问你:"你重写过 hashcode 和 equals 么,为什么重写equals时必须重写hashCode方法?" 1 ...

  3. 记EF的一个基本访问类

    代码: 1 using EFModel; 2 using System; 3 using System.Collections.Generic; 4 using System.Data.Entity; ...

  4. 数据结构 - 二叉树的遍历(递归VS非递归)

    import java.util.LinkedList; public class BinaryTree { public static void main(String[] args) { int ...

  5. solr 文档二

    SOLR 5.5.5文档 参考博文: http://blog.csdn.net/matthewei6/article/details/50620600 作者:毛平 时间:2018年1月15日 17:3 ...

  6. 4G模块与WIFI模块的工作及应用区别

    在物联网行业中,4G模块和wifi模块经经常会被使用,但是由于网络不同,二者的工作原理和场景还是有很大的不同,本篇主要讲讲4G模块和WIFI模块的功能和应用场景 什么是4G模块? 4G模块是基于4G网 ...

  7. Desition Tree附代码

  8. php判断手机浏览器和pc浏览器

    <?php public function is_mobile(){ // returns true if one of the specified mobile browsers is det ...

  9. nginx&http 第三章 ngx 事件event accept epoll /init

    tcp 三次握手成功后,listen fd  可读,在process_event_timer 中调用rev->handler(rev)处理: 其回调函数为: ngx_event_accept / ...

  10. 378. Kth Smallest Element in a Sorted Matrix(大顶堆、小顶堆)

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...