目录
spring5.x体系架构
Data Access/Integration: 数据访问/集成模块:提供对数据源操作的支持,包括对jdbc、orm映射框架、xml解析、消息队列、事务管理的支持。
Web模块:提供对web应用的支持
Core Container 核心容器模块:实现spring容器,主要提供IoC/DI功能
AOP模块:提供对面向切面编程(AOP)的支持
Test 测试模块:提供对测试的支持
在线说明文档学习:
http://docs.jcohy.com/docs/spring-framework/5.3.22/html5/zh-cn/index.html
搭建阅读环境相关准备
名称 |
信息 |
备注 |
maven版本 |
3.x |
|
idea版本 |
2019或以上 |
|
jdk版本 |
1.8+ |
一般使用1.8 |
spring源码版本 |
V5.2.7(5.x都可以) |
地址:https://github.com/spring-projects/spring-framework/tree/v5.2.7.RELEASE |
gradle |
用idea自带就OK |
下载spring:https://github.com/spring-projects/spring-framework/tree/v5.2.7.RELEASE
注意:git如果慢可以用手动下载。
版本介绍
名称 |
描述 |
备注 |
alpha |
用于内测版,bug比较多,不稳定,不断更新 |
一般不使用 |
beta1、beta2... |
用于公测版,不稳定比alpha版稳定一点,不断更新功能 |
一般不使用 |
RC |
用于候选版本,经过多个beta版本,较稳定,用于准备修复完bug进入正式发布版 |
测试使用 |
M1、M2.. |
里程碑版本,一般是有大改进的版本。 |
较少使用 |
GA、RELEASE、Stable、Final等 |
用于生产版本,稳定版。 |
最终使用版 |
源码编译
配置项目
下载的包解压并打开位置:spring-framework-5.2.7.RELEASE\gradle\wrapper
打开gradle-wrapper
修改配置:pring-framework-5.2.7.RELEASE 下面的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" }
}
屏蔽代码plugins下面的id 'io.spring.gradle-enterprise-conventions' version '0.0.2' 避免下载gradle失败。
进入编译
1.进行编译
在根目录打开cmd 然后执行如下:
gradlew :spring-oxm:compileTestJava
结果如下:
提示:BUILD SUCCESSFUL 就是成功。
2.导入idea进行编译
导入idea中进行编译。
需要等待较长时间编译(有点久)
构建完成后
3.最后测试代码
新建模块
选择gradle
填写自定义模块名称
打开build.gradle (spring-hong-testing) 添加依赖如下:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile(project(":spring-context"))
}
添加测试代码
package com.hong.service;
/**
* @ClassName TestIService
* @Description 测试服务
* @Author csh
* @Date 2023/1/11 14:37
*/
public interface TestIService {
void testSpringSourceBuild();
}
package com.hong.service.impl;
import org.springframework.stereotype.Service;
import com.hong.service.TestIService;
/**
* @ClassName TestIServiceImpl
* @Description spring验证类实现
* @Author csh
* @Date 2023/1/11 14:39
*/
@Service
public class TestIServiceImpl implements TestIService {
@Override
public void testSpringSourceBuild() {
System.out.println("spring build success!");
}
}
package com.hong;
import com.hong.service.impl.TestIServiceImpl;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* @ClassName TestMain
* @Description 测试
* @Author csh
* @Date 2023/1/11 14:45
*/
@Configuration
@ComponentScan("com.hong")
public class TestMain {
public static void main(String[] args) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext((TestMain.class));
TestIServiceImpl bean = applicationContext.getBean(TestIServiceImpl.class);
bean.testSpringSourceBuild();
}
}
结果
> Task :spring-hong-testing:classes
> Task :spring-hong-testing:TestMain.main()
spring build success��
BUILD SUCCESSFUL in 50s
35 actionable tasks: 2 executed, 33 up-to-date
The remote build cache was disabled during the build due to errors.
14:57:52: Task execution finished 'TestMain.main()'.
最后搭建好以上的环境可以接下来源码学习。参考文章:https://blog.csdn.net/weixin_39786760/article/details/125133008https://www.cnblogs.com/lusaisai/p/11686352.htmlhttps://www.jianshu.com/p/949bb16813a2