spring5.x介绍及搭配spring源码阅读环境

查看源文

目录

spring5.x体系架构

版本介绍

源码编译

配置项目

进入编译


spring5.x体系架构

915afafa63442e0c79281e26d69c81d6.png

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

b27fc1ac173f1948147f089d42626262.png

43ca961c9f02e16d9a3a9cf10e455b0f.png

注意:git如果慢可以用手动下载。

d5f21c01db88026c79df21c6a4f5303d.png

版本介绍

名称

描述

备注

alpha

用于内测版,bug比较多,不稳定,不断更新

一般不使用

beta1、beta2...

用于公测版,不稳定比alpha版稳定一点,不断更新功能

一般不使用

RC

用于候选版本,经过多个beta版本,较稳定,用于准备修复完bug进入正式发布版

测试使用

M1、M2..

里程碑版本,一般是有大改进的版本。

较少使用

GA、RELEASE、Stable、Final等

用于生产版本,稳定版。

最终使用版

源码编译

配置项目

下载的包解压并打开位置:spring-framework-5.2.7.RELEASE\gradle\wrapper

765f7e4dab0582b324b9bbdc081fe1b3.png

009f13eec7ae94472ddf6add91767795.png

打开gradle-wrapper

dcd2e6c8bf23c80c44ed28f70a1083e1.png

修改配置: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失败。ebfb8be528d982c5f1bda8bb6b14d6fc.png

进入编译

1.进行编译

在根目录打开cmd 然后执行如下:

gradlew :spring-oxm:compileTestJava

结果如下:

7cbf47254914606089c0cfba0d297631.png

提示:BUILD SUCCESSFUL 就是成功。

2.导入idea进行编译

导入idea中进行编译。

cbf7050b97d56eec8b1cdc218bfb423c.png

需要等待较长时间编译(有点久)

40ffe4e7be4f9e2f2b78b81dff2e4e04.png

构建完成后

0643071d7504fdf5db31b61d27c8c3d7.png

3.最后测试代码

新建模块

f1fd6687625d589bf75acb0a2311440a.png

选择gradle

d31b827e1c6411ba85e4a871ac4bcc26.png

填写自定义模块名称

43ee1f1833a7fd9ed167b04fc00aa381.png

打开build.gradle (spring-hong-testing) 添加依赖如下:

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile(project(":spring-context"))
}
添加测试代码

177d56069d1e206b05f01eeb42914c9a.png

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();
  }
}

结果

3d2b4e7ce04e816552a825c272975e1a.png

> 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

猜你喜欢

转载自blog.csdn.net/qq_16498553/article/details/129117020