IDEA2021 Spring 源码编译

Spring 源码编译

心血来潮突然想看下spring的源码,我用的是idea2021,spring版本是5.2.x,但是网上基本上都是以前的版本,所以想记录一下。

1.下载spring源码

在码云上通过git克隆源码https://gitee.com/mirrors/Spring-Framework.git

2.下载gradle

查看Spring-Framework/gradle/wrapper/gradle-wrapper.properties文件对应的gradle的版本号。
在这里插入图片描述
并自行去gradle官网下载,找到对应的版本号。
在这里插入图片描述
3.配置gradle环境变量

vim ~/.bash_profile
我是mac,配置环境变量类似jdk,不会可百度。
在这里插入图片描述
重新加载配置
source ~/.bash_profile
验证安装
gradle -v
在这里插入图片描述

3.编译源码

./gradlew :spring-oxm:compileTestJava
在这里插入图片描述

4.导入源码

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

5.新建测试module

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

引入依赖

我是将spring-test的依赖直接拿过来的
在这里插入图片描述
在这里插入图片描述

description = "Spring DebugContext Framework"

apply plugin: "kotlin"

dependencies {
    compile(project(":spring-core"))
    optional(project(":spring-aop"))
    optional(project(":spring-beans"))
    optional(project(":spring-context"))
    optional(project(":spring-jdbc"))
    optional(project(":spring-orm"))
    optional(project(":spring-tx"))
    optional(project(":spring-web"))
    optional(project(":spring-webflux"))
    optional(project(":spring-webmvc"))
    optional(project(":spring-websocket"))
    optional(project(":spring-instrument"))
    optional("javax.activation:javax.activation-api")
    optional("javax.el:javax.el-api")
    optional("javax.inject:javax.inject")
    optional("javax.servlet:javax.servlet-api")
    optional("javax.servlet.jsp:javax.servlet.jsp-api")
    optional("javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api")
    optional("javax.xml.bind:jaxb-api")
    optional("javax.websocket:javax.websocket-api")
    optional("junit:junit")
    optional("org.junit.jupiter:junit-jupiter-api")
    optional("org.testng:testng")
    optional("org.aspectj:aspectjweaver")
    optional("org.codehaus.groovy:groovy")
    optional("org.hamcrest:hamcrest")
    optional("org.apache.taglibs:taglibs-standard-jstlel")
    optional("net.sourceforge.htmlunit:htmlunit")
    optional("org.seleniumhq.selenium:htmlunit-driver")
    optional("org.seleniumhq.selenium:selenium-java")
    optional("org.xmlunit:xmlunit-matchers")
    optional("org.skyscreamer:jsonassert")
    optional("com.jayway.jsonpath:json-path")
    optional("org.jetbrains.kotlin:kotlin-reflect")
    optional("org.jetbrains.kotlin:kotlin-stdlib")
    optional("io.projectreactor:reactor-test")
    optional("org.jetbrains.kotlinx:kotlinx-coroutines-core")
    optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
    testCompile(project(":spring-context-support"))
    testCompile(project(":spring-oxm"))
    testCompile(testFixtures(project(":spring-beans")))
    testCompile(testFixtures(project(":spring-context")))
    testCompile(testFixtures(project(":spring-core")))
    testCompile(testFixtures(project(":spring-tx")))
    testCompile(testFixtures(project(":spring-web")))
    testCompile("javax.annotation:javax.annotation-api")
    testCompile("javax.cache:cache-api")
    testCompile("javax.ejb:javax.ejb-api")
    testCompile("javax.interceptor:javax.interceptor-api")
    testCompile("javax.mail:javax.mail-api")
    testCompile("org.hibernate:hibernate-core")
    testCompile("org.hibernate:hibernate-validator")
    testCompile("javax.validation:validation-api")
    testCompile("org.junit.platform:junit-platform-runner") {
        exclude group: "junit", module: "junit"
    }
    testCompile("org.junit.platform:junit-platform-testkit")
    testCompile("com.fasterxml.jackson.core:jackson-databind")
    testCompile("com.thoughtworks.xstream:xstream")
    testCompile("com.rometools:rome")
    testCompile("org.apache.tiles:tiles-api")
    testCompile("org.apache.tiles:tiles-core")
    testCompile("org.apache.tiles:tiles-servlet")
    testCompile("org.hsqldb:hsqldb")
    testCompile("org.apache.httpcomponents:httpclient")
    testCompile("io.projectreactor.netty:reactor-netty")
    testCompile("de.bechte.junit:junit-hierarchicalcontextrunner")
    testRuntime("org.junit.vintage:junit-vintage-engine") {
        exclude group: "junit", module: "junit"
    }
    testRuntime("org.glassfish:javax.el")
    testRuntime("com.sun.xml.bind:jaxb-core")
    testRuntime("com.sun.xml.bind:jaxb-impl")
}

添加测试类

在这里插入图片描述

package org.springframework.bean;

/**
 * @author fangjianfeng
 * @date 2021-07-20.
 */
public class MyBean {
	private String id;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
	<bean id="myBean" class="org.springframework.bean.MyBean"></bean>
</beans>

运行成功
在这里插入图片描述

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author fangjianfeng {@literal <jianfeng.fang@leyantech.com>}
 * @date 2021-07-20.
 */
public class TestBean {
	@Test
	void testSimpleLoad() {
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");
		Object myBean = applicationContext.getBean("myBean");
		System.out.println(myBean);
	}

}

6.注意事项

建完测试类运行的时候每次启动都会编译一次,试了好多方法都不管用,最后尝试下面方式得以解决。
在这里插入图片描述
在这里插入图片描述
勾选完idea编译后再次运行demo时可能会报各种类找不到的错误,我们只要找到报错的项目进行编译就好了。
在这里插入图片描述
我就是按这样的方法解决的~

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值