元月's blog 元月's blog
首页
  • 基础
  • 并发编程
  • JVM
  • Spring
  • Redis篇
  • Nginx篇
  • Kafka篇
  • Otter篇
  • Shardingsphere篇
  • 设计模式
  • MySQL
  • Oracle
  • 基础
  • 操作系统
  • 网络
  • 数据结构
  • 技术文档
  • Git常用命令
  • GitHub技巧
  • 博客搭建
  • 开发工具
更多

元月

临渊羡鱼,不如退而结网
首页
  • 基础
  • 并发编程
  • JVM
  • Spring
  • Redis篇
  • Nginx篇
  • Kafka篇
  • Otter篇
  • Shardingsphere篇
  • 设计模式
  • MySQL
  • Oracle
  • 基础
  • 操作系统
  • 网络
  • 数据结构
  • 技术文档
  • Git常用命令
  • GitHub技巧
  • 博客搭建
  • 开发工具
更多
  • Spring

    • SpringFramework源码编译
      • 前言
      • 一、下载SpringFramework5.3.10源码
      • 二、下载Spring源码所需要的依赖
      • 三、配置idea相关
        • 1、将下载下来的依赖放到自己指定的Gradle user home中,此处为/Users/ruanyou,并解压
        • 2、修改Build and run using 和 Run tests using为 IDEA
        • 3、注释spring-core模块中jfr相关的代码,jdk8版本不支持。然后点击build,构建成功就可以了
      • 四、运行代码
        • 1、新增测试模块 ruanyou-spring-framework-5.3.10
        • 2、引入依赖和增加测试类
        • 3、启动测试代码
      • 五、常见问题
        • 1、程序包jdk.jfr不存在
    • Spring事件监听机制
    • SpringMVC之Servlet的生命周期和工作原理
    • SpringMVC的执行过程
    • SpringMVC的常用注解和使用场景
  • Java进阶
  • Spring
元月
2022-07-27
目录

SpringFramework源码编译

# SpringFramework源码编译

# 前言

前前后后,看过几次Spring的源码,但是过一段时间,许多细节都遗忘了,因此特意在我的github项目中,新建了SpringFramework一个项目spring-framework5.3.10 (opens new window),用来跟进Spring相关的底层源码,以及写一些自己的源码注释

# 一、下载SpringFramework5.3.10源码

我们可以去SpringFramework的releases (opens new window)页面搜索下载相应的版本源码,这里我下载的是Spring-framework-v5.3.10 (opens new window)

img.png

img_1.png

# 二、下载Spring源码所需要的依赖

Spring是通过gradle来编译源码下载依赖的,.gradle⽂件夹可以理解为gradle的仓库(和maven类似)。

Spring源码存在很多依赖包,当时引入依赖时,耗费了我许多时间,这里将需要的依赖打个包,方便下次快速处理依赖

链接: https://pan.baidu.com/s/1SiXMe6wvy8qPGJJCYf1Sxg 密码: kjqb

# 三、配置idea相关

img_3.png

# 1、将下载下来的依赖放到自己指定的Gradle user home中,此处为/Users/ruanyou,并解压

# 2、修改Build and run using和 Run tests using为 IDEA

# 3、注释spring-core模块中jfr相关的代码,jdk8版本不支持。然后点击build,构建成功就可以了

img_5.png img_6.png

# 四、运行代码

# 1、新增测试模块 ruanyou-spring-framework-5.3.10

img_4.png

# 2、引入依赖和增加测试类

build.gradle文件如下:

plugins {
    id 'java'
}

group 'org.springframework'
version '5.3.10'

repositories {
    mavenCentral()
}

dependencies {
    api(project(":spring-context"))
    api(project(":spring-beans"))
    api(project(":spring-core"))
    optional("org.apache.commons:commons-pool2")
    optional("com.jamonapi:jamon")
    testImplementation(testFixtures(project(":spring-beans")))
    testImplementation(testFixtures(project(":spring-core")))
    testFixturesImplementation(testFixtures(project(":spring-beans")))
    testFixturesImplementation(testFixtures(project(":spring-core")))
}

test {
    useJUnitPlatform()
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

OrderService.java

import org.springframework.stereotype.Component;

@Component
public class OrderService {

	public void test(){
		System.out.println("123123");
	}

}
1
2
3
4
5
6
7
8
9
10

AppConfig.java

import org.springframework.context.annotation.ComponentScan;

@ComponentScan("com.ruanyou")
public class AppConfig {

}
1
2
3
4
5
6

Test.java

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Test {
	public static void main(String[] args) {
		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
		OrderService orderService = applicationContext.getBean("orderService",OrderService.class);
		System.out.println(orderService);
	}
}
1
2
3
4
5
6
7
8

# 3、启动测试代码

img_7.png

# 五、常见问题

# 1、程序包jdk.jfr不存在

注释spring-core模块中jfr相关的代码,jdk8版本不支持。然后点击build,构建成功就可以了

#Spring
Spring事件监听机制

Spring事件监听机制→

最近更新
01
otter二次开发-支持按目标端主键索引Load数据
08-03
02
mvnw简介
06-21
03
gor流量复制工具
06-03
更多文章>
Theme by Vdoing | Copyright © 2022-2024 元月 | 粤ICP备2022071877号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式