# spring-boot-2.2.13 **Repository Path**: samsource/spring-boot-2.2.13 ## Basic Information - **Project Name**: spring-boot-2.2.13 - **Description**: 一窥springboot2.2.13源码 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-02-17 - **Last Updated**: 2023-03-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README https://blog.csdn.net/zhang_didi/article/details/122713103 ### 前言 ``` 想研究Spring Boot源码,最好能在本地进行编译,同时在分析源码的时候,可以添加自己的注释,接下来,我们先来搭建一下我们本地源码环境。 由于Spring Boot源码项目在2.3.0版本之前都是用的Maven构建的,在2.3.0版本之后改用Gradle构建项目。 为了简单省事,本文选择了SpringBoot2.2.13版本的源码进行编译,因为我们大部分人使用的都是Maven,省去了安装Gradle环境的环节。 ``` ### 1.源码下载 ``` https://github.com/spring-projects/spring-boot spring-boot-2.2.13.RELEASE.zip #xattr -c -r spring-boot-2.2.13.RELEASE.zip ``` ### 2.本地编译 ``` 我们将下载的Spring Boot源码解压,添加到自己的git仓库上。 cd ~/IntelliJProjects/samsource/spring-boot-2.2.13.RELEASE git init git add -A git commit -m "first commit" git checkout -b master git remote add origin https://gitee.com/samsource/spring-boot-2.2.13.git git push -u origin "master" git branch -d main ``` #### 2.1 修改根pom文件 IDEA打开工程 1.首先,我们先将pom文件上添加一个 disable.checks属性并将其设置成true,可以在编译源码的时候关闭maven的代码检查。 ``` 2.2.13.RELEASE ${basedir} true ``` 如何不设置disable.checks属性的话,那么在Maven编译打包的时候,就需要忽略maven的代码检查。 #### 2.2 编译源码 ``` mvn clean install -DskipTests -Pfast 如果失败,尝试多编译几次 有标红的不用的插件可以直接注释掉 ``` ### 3.源码环境的使用 ``` 既然编译好了Spring Boot源码,那么我们就可以来创建我们自己的Spring Boot项目了, 当然创建的Spring Boot项目最好和我们编译的源码版本一致。 创建自己的Spring Boot项目并关联我们编译好的源码,一般有两种方式: 一种是直接在源码工程中创建我们的项目作为源码工程中的一个模块; 另一种就是单独创建一个Spring Boot工程,将源码导入到该工程中。 ``` #### 3.1 源码的工程下创建Spring Boot项目 ``` 创建新的Maven模块 创建一个module spring-boot-pocs 右击——>New ——> Module ——> maven ——>注意父模块 这个界面不用操作,直接点下一步 我们创建个模块spring-boot-mytest 并将pom中parent中spring boot的版本改成2.2.9.RELEASE.POC。 此时,我们的demo项目可以成功运行。在查看Spring Boot中的注解时,直接点击就可以跳到源码部分。 当然了,我们只编译了Spring Boot的源码,对于Spring的注解,我们还是看不了的。 ``` #### 3.2 在独立的项目中导入源码 ``` 在独立的Spring Boot工程中使用我们编译之后的源码,可能更方便大家来针对源码的功能进行调试。 在创建Spring Boot的demo工程时,使用的版本最好和我们编译的Spring Boot版本一致。 1.先创建2.2.X.RELEASE版本的spring boot项目;(https://start.aliyun.com/) 2.将编译好的2.2.9.RELEASE.POC版本的源码导入到项目; 依次点击IDEA->File->Project Structure, 找到Project settings下的Libraries,在libraries中找到spring boot并点击, 在右侧的+里面找到我们源码编译的目录,并选择导入即可。 I want to edit all files in this directory 这个时候在独立项目中改的内容会同步到这里的额 ``` #### 3.3 刚拉取下来的代码可能会出现idea无法识别module模块的问题。 ``` 现在主工程的pom.xml中刷新,然后再去对应的子工程的pom.xml中刷新 ```