Spring5.x introduction and matching spring source code reading environment

view source

Table of contents

spring5.x architecture

version introduction

source code compilation

configuration items

enter compile


spring5.x architecture

915afafa63442e0c79281e26d69c81d6.png

Data Access/Integration: Data Access/Integration Module: Provides support for data source operations, including support for jdbc, orm mapping framework, xml parsing, message queue, and transaction management.

Web module: provides support for web applications

Core Container core container module: implement spring container, mainly provide IoC/DI function

AOP module: Provides support for aspect-oriented programming (AOP)

Test test module: provides support for testing

Online documentation study:

http://docs.jcohy.com/docs/spring-framework/5.3.22/html5/zh-cn/index.html

Preparations for building a reading environment

name

information

Remark

maven version

3.x

idea version

2019 or above

jdk version

1.8+

Generally use 1.8

spring source code version

V5.2.7 (5.x can be used)

Address: https://github.com/spring-projects/spring-framework/tree/v5.2.7.RELEASE

gradle

It is OK to use the idea

下载spring:https://github.com/spring-projects/spring-framework/tree/v5.2.7.RELEASE

b27fc1ac173f1948147f089d42626262.png

43ca961c9f02e16d9a3a9cf10e455b0f.png

Note: If git is slow, you can download it manually.

d5f21c01db88026c79df21c6a4f5303d.png

version introduction

name

describe

Remark

alpha

For the internal test version, there are many bugs, unstable, and constantly updated

generally not used

beta1、beta2...

For the public beta version, it is more unstable than the alpha version, and the function is constantly updated

generally not used

RC

It is used for the candidate version, after several beta versions, it is relatively stable, and it is used to prepare for the official release after fixing bugs

test use

M1、M2..

Milestone versions are generally versions with major improvements.

less used

GA、RELEASE、Stable、Final等

For production releases, stable releases.

end use version

source code compilation

configuration items

Unzip the downloaded package and open the location: spring-framework-5.2.7.RELEASE\gradle\wrapper

765f7e4dab0582b324b9bbdc081fe1b3.png

009f13eec7ae94472ddf6add91767795.png

open gradle-wrapper

dcd2e6c8bf23c80c44ed28f70a1083e1.png

Modify the configuration: build.gradle under pring-framework-5.2.7.RELEASE The new configuration is as follows, add the Aliyun warehouse

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" }
    }

Shield the id 'io.spring.gradle-enterprise-conventions' version '0.0.2' under the code plugins to avoid failure to download gradle.ebfb8be528d982c5f1bda8bb6b14d6fc.png

enter compile

1. Compile

Open cmd in the root directory and execute as follows:

gradlew :spring-oxm:compileTestJava

The result is as follows:

7cbf47254914606089c0cfba0d297631.png

Tip: BUILD SUCCESSFUL means success.

2. Import idea to compile

Import idea to compile.

cbf7050b97d56eec8b1cdc218bfb423c.png

Need to wait for a long time to compile (a bit long)

40ffe4e7be4f9e2f2b78b81dff2e4e04.png

After the build is complete

0643071d7504fdf5db31b61d27c8c3d7.png

3. Finally test the code

new module

f1fd6687625d589bf75acb0a2311440a.png

select gradle

d31b827e1c6411ba85e4a871ac4bcc26.png

Fill in the custom module name

43ee1f1833a7fd9ed167b04fc00aa381.png

Open build.gradle (spring-hong-testing) and add dependencies as follows:

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile(project(":spring-context"))
}
add test code

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

result

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()'.

Finally, after setting up the above environment, you can learn from the source code. Reference article: https://blog.csdn.net/weixin_39786760/article/details/125133008https://www.cnblogs.com/lusaisai/p/11686352.htmlhttps://www.jianshu.com/p/949bb16813a2

Guess you like

Origin blog.csdn.net/qq_16498553/article/details/129117020