本文记录了 Spring 源码阅读环境的搭建方式
环境准备
- Git
- JDK8
- Gradle
- IntelliJ IDEA 2020.1
注意:
- Spring master分支需要 JDK11,5.2.x 分支 使用 JDK8 即可
下载源码
先 fork 到自己的仓库,然后使用 git clone 下载源码。
注意:这里必须使用 git clone 的方式下载,而不是下载 zip 包的方式,否则会构建失败
指定 clone 5.2.x 的代码:
1 | git clone -b 5.2.x https://github.com/jaceding/spring-framework.git |
导入IDEA
使用 IDEA 打开

等待 IDEA 加载,一般此时 IDEA 会自动构建
导入时配置IDEA Gradle:

构建

测试
在项目右键创建 module

选择 Gradle
Java

填写module信息

在 module 中的 build.gradle 中添加配置:
1 | compile(project(":spring-context")) |
效果:
1 | plugins { |
创建测试类 Application:
1 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
执行后输出如下:

遇到的问题
问题1
在源码中添加中文注释后,启动出现乱码:

解决办法:

添加:
1 | -Dfile.encoding=utf-8 |

最终重启 IDEA