sping源码在IDEA中编译最新方法,版本5.0.X

本文详细介绍了如何从GitHub获取Spring 5.0版本的源码,并使用Gradle进行编译的过程。包括解决repo.spring.io访问限制的问题、配置阿里云镜像地址、处理编译过程中的常见错误等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.版本说明

spring版本:5.0.X
gradle版本:4.10.1
gradle大于等于spring要求版本,具体在gradle/wrapper/gradle-wrapper.properties 这个目录下查看

步骤

1)获取源码

克隆
git clone git@github.com:cracker13/spring-framework.git
这里是我从spring官方GitHub上fork的地址,以后给源码写注释就可以传到自己的仓库上看了。当然你要是没这需求直接从官方上拉取
git clone https://github.com/spring-projects/spring-framework.git

获取历史提交记录
git log v5.0.20.RELEASE
得到sha值

回退版本
git checkout 0cd0d2e8be90fbf9d6efe6572c23c2d14f32ff0a

成功,控制台打印出了
Release version 5.0.20.RELEASE

2)配置IDEA的gradle

3)导入源码
open->选中目录打开即可

4)开始编译

会发现无法下载一些包。因为repo.spring.io这个站点被限制访问了,所以我们需要配镜像地址

5)配置镜像地址
找到build.gradle这个文件
全文搜索repositories有2处地方,一块是配插件地址的,改成阿里镜像地址

repositories {
		gradlePluginPortal()
//		maven { url "https://repo.spring.io/plugins-release" }
                maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
		maven { url "https://maven.aliyun.com/repository/spring-plugin" }

	}

还有一块是普通仓库地址,也改成阿里镜像地址

repositories {
		mavenCentral()
//		maven { url "https://repo.spring.io/libs-spring-framework-build" }
		maven { url "https://maven.aliyun.com/repository/central" }
		maven { url "https://maven.aliyun.com/repository/public" }
		maven { url 'https://maven.aliyun.com/repository/spring' }
	}

注意:4、5步骤不能颠倒,因为有一些包只有先从repo.spring.io下载的才能正常使用。

6)再次编译
过程中会出错
错误1
No such property: values for class: org.gradle.api.internal.tasks.DefaultTaskDependency
直接点open file,把其中一行注释掉

错误2

Error:Kotlin: [Internal Error] java.lang.IllegalStateException: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler

Caused by: java.lang.AbstractMethodError: org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar.registerProjectComponents(Lcom/intellij/mock/MockProject;Lorg/jetbrains/kotlin/config/CompilerConfiguration;)V

插件版本太旧去升级下kotlin插件

错误3
单元测试(后面会写),再报错

Error:(20, 50) java: 程序包org.springframework.objenesis.instantiator不存在

cmd进入spring-core所在目录,手动安装jar包

gradle objenesisRepackJar
gradle cglibRepackJar

参考:https://blog.csdn.net/u010999809/article/details/90444714

编写测试模块

新建module->gradle,后面我截个图,贴下代码,具体不写了

package com.cracker.bean;

import java.util.List;
import java.util.Map;
import java.util.Properties;

public class Person {

	private String lastName;
	private Integer age;
	private String gender;

	public Person() {
	}

	public Person(String lastName, Integer age, String gender) {
		this.lastName = lastName;
		this.age = age;
		this.gender = gender;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	@Override
	public String toString() {
		return "Person{" +
				"lastName='" + lastName + '\'' +
				", age=" + age +
				", gender='" + gender + '\'' +
				'}';
	}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="person01" class="com.cracker.bean.Person">
		<property name="lastName" value="张三"></property>
		<property name="age" value="18"></property>
		<property name="gender" value=""></property>
	</bean>
</beans>
package com.cracker.test;

import java.util.List;
import java.util.Map;

import com.cracker.bean.Person;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class IOCTest {

	@Test
	public void test() {

		ApplicationContext ioc = new ClassPathXmlApplicationContext("ioc.xml");

		System.out.println("容器启动完成....");
		Person bean = (Person) ioc.getBean("person01");
		System.out.println(bean);
		}

}

结束

然后就可愉快学习spring源码了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值