关于spring:Spring-源码阅读环境的搭建

4次阅读

共计 1721 个字符,预计需要花费 5 分钟才能阅读完成。

前言

本文记录了 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-pro…
  2. Spring 构建文档:https://github.com/spring-pro…

历史文章

  • ReentrantLock 源码、画图一起看一看!
  • ReentrantReadWriteLock 的原理!
  • Spring 自调用事务生效,你是怎么解决的?
正文完
 0