Spring源码编译

一、下载源码

在github或者gitee上下载spring-framework的特定版本的源码,这里选择5.3.8版本,openjdk的版本为8以上。新版本用的是gradle 7,添加依赖的命令不熟悉,故使用gradle 6版本进行编译。

二、配置仓库地址

下载好源码之后,解压并修改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模块,编译命令如下:

gradlew :spring-oxm:compileTestJava

编译成功如下图所示,图中出现错误忽略即可。
在这里插入图片描述

四、导入IDEA编译

将源码导入idea,修改settings.gradle文件,将spring-aspects模块注释掉。之后等待idea自动下载gradle并开始编译,网速良好的情况下等待大概几分钟时间,编译成功。在这里插入图片描述在这里插入图片描述在这里插入图片描述

五、测试

新建module,添加依赖,创建测试类。

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
    compile(project(":spring-context"))
    compile(project(":spring-beans"))
}
public class Test {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(UserServiceImpl.class);
        applicationContext.refresh();
        UserService userService = applicationContext.getBean(UserService.class);
        userService.sayHello();
    }
}
public interface UserService {
	void sayHello();
}
public class UserServiceImpl implements UserService{
	@Override
	public void sayHello() {
		System.out.println("成功编译Spring源码!!!!!");
	}
}

输出测试结果:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zerooooooooooooooooo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值