1. Spring源码编译配置
1.1 IDEA Kotlin插件安装
1.2 Gradle安装
-
配置gradle环境变量GRADLE_HOME
-
Path配置项增加
%GRADLE_HOME%\bin
-
IDEA配置Gradle
1.3 Spring源码下载
首先进入目录 cd E:\IdeaProjectsStudy\spring-framework\5.2.8
将源码下载到该路径下
执行命令:
git clone --branch v5.2.8.RELEASE https://gitee.com/gumj/spring-framework.git
-
修改
settings.gradle
repositories { gradlePluginPortal() //增加此行,配置阿里云仓库 maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://repo.spring.io/plugins-release' } }
-
修改gradle.properties
version=5.2.8.RELEASE org.gradle.jvmargs=-Xmx2048M org.gradle.caching=true org.gradle.parallel=true org.gradle.configureondemand=true org.gradle.daemon=true
-
修改build.gradle
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" } }
-
编译spring-oxm模块
//在cmd窗口中执行以下命令 cd E:\IdeaProjectsStudy\spring-framework\5.2.8\spring-framework gradlew :spring-oxm:compileTestJava
由于自动下载gradle-5.6.4-bin.zip非常慢,所以在执行命令后按Ctrl+C取消下载操作,将下载链接地址拷贝后直接手动下载文件,然后将下载的gradle-5.6.4-bin.zip压缩包拷贝到gradle仓库目录,在执行
gradlew :spring-oxm:compileTestJava
命令时会自动在仓库下创建文件夹gradle-5.6.4-bin\bxirm19lnfz6nurbatndyydux
,只需将下载好的gradle-5.6.4-bin.zip压缩包拷贝到该路径下即可,然后重新执行gradlew :spring-oxm:compileTestJava命令。我的gradle仓库路径是:
E:\Gradle_Repository\wrapper\dists\gradle-5.6.4-bin\bxirm19lnfz6nurbatndyydux
-
IDEA导入Spring源码
1.4 配置已编译的源码路径
-
找到指定的jar包,右键点击Open Library Settings
-
将仓库中的jar包路径删除,添加已编译的jar包路径,和源码路径
下图为配置成功后的样子
进入ClassPathXmlApplicationContext.java文件可以编写注释
-
按照上面的步骤完成操作,就可以对源码在debug时进行修改了,下面是测试启动方法。
@Data public class Student { private String username = "test"; }
spirng.xml配置
<bean id="student" class="com.gumj.spring.bean.Student"/>
测试方法
@Test public void test1() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml"); Student bean = applicationContext.getBean(Student.class); System.out.println(bean.getUsername()); }