1. 从github上获取spring源码
github官方仓库地址 :https://github.com/spring-projects/spring-framework/tree/v5.2.8.RELEASE
打开后,点击tag,
这里我选择是的5.2.8的发布版本,也可以选择其他版本进行下载。

然后把整个项目 clone 到本地。
2. 准备工作
2.1. 添加为gradle项目
打开刚才clone下来的项目,可以看到spring源码工程 不是 用的 maven 来管理依赖的, 而是gradle。

如果没有安装gradle,会提示你安装,点安装即可。
如果idea没有识别出来的话,就自己手动添加一下gradle配置的配置,就跟maven项目选择pom一样。
2.2. 修改build.gradle
-
添加阿里云仓库地址
由于spring5.x之后,官方仓库需要认证,如果不换阿里云的仓库的话,获取依赖的话会报401.
打开build.gradle 文件, 修改 configure(allprojects) { project -> dependencyManagement 闭包内的 repositories,
5.1.x版本还需要修改该文件下的,buildscript{}闭包内的repositories{}。(5.2.8没有这个配置)
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
mavenCentral()
maven { url "https://repo.spring.io/libs-spring-framework-build" }
}
- 如果导包的过程出现莫名其妙的错误,把这行注释掉。

2.3、添加settings.gradle 阿里云插件仓库

// 在该位置,加上这行
maven { url 'https://repo.spring.io/plugins-release' }
3. 获取依赖 ,打包
3.1.获取依赖
点这个按钮,获取依赖

所以依赖获取成功之后,界面是这样的

3.2.打包
选择某个模块, 点jar,进行打包

4.更改测试项目的依赖spring的jar包和源文件位置
某个模块打包后之后,会在 其项目路径/对应模块/build/libs 目录下生成打包出来的 xxxx.jar

比如我们的测试代码
@Test
public void test(){
ApplicationContext applicationContext = new AnnotationConfigApplicationContext("com.lb.springboot_simple_starter");
}
要把AnnotationConfigApplicationContext这个类的引用变为我们 刚才编译好的源码
- 点进去查看这个类在哪个jar包下

- 右键该jar包, 点Open Library Settings

- 修改 class 为刚才 打包源码生成的jar ,并移除掉原来的。


- 修改source 为 源码项目 对应模块下的src文件


这样下次看类的源码就可以直接点进到 我们的源码项目里,可以debugger调试,以及打注释, 打完注释之后,重新打包一下即可。

大功告成了!!!!
网友评论