Spring5.x の導入とそれに対応した Spring ソースコード読み取り環境

ソースを見る

目次

spring5.x アーキテクチャ

バージョン紹介

ソースコードのコンパイル

設定項目

コンパイルを入力してください


spring5.x アーキテクチャ

915afafa63442e0c79281e26d69c81d6.png

データ アクセス/統合:データ アクセス/統合モジュール: jdbc、orm マッピング フレームワーク、xml 解析、メッセージ キュー、トランザクション管理のサポートを含む、データ ソース操作のサポートを提供します。

Web モジュール: Web アプリケーションのサポートを提供します

Core Container コアコンテナモジュール: Springコンテナを実装し、主にIoC/DI機能を提供します

AOP モジュール:アスペクト指向プログラミング (AOP) のサポートを提供します。

テストテストモジュール:テストのサポートを提供します。

オンラインでのドキュメントの調査:

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

読書環境を構築するための準備

名前

情報

述べる

メイブンのバージョン

3.x

アイデアバージョン

2019年以降

JDKのバージョン

1.8+

通常は 1.8 を使用します

Spring のソースコードのバージョン

V5.2.7(5.xも使用可能)

アドレス: https://github.com/spring-projects/spring-framework/tree/v5.2.7.RELEASE

グラドル

アイデアを使ってもOKです

Spring のダウンロード:https://github.com/spring-projects/spring-framework/tree/v5.2.7.RELEASE

b27fc1ac173f1948147f089d42626262.png

43ca961c9f02e16d9a3a9cf10e455b0f.png

注: git が遅い場合は、手動でダウンロードできます。

d5f21c01db88026c79df21c6a4f5303d.png

バージョン紹介

名前

説明

述べる

アルファ

内部テスト版のため、バグが多く、不安定で、常に更新されています

一般的には使用されません

ベータ1、ベータ2...

パブリックベータ版はアルファ版に比べて不安定であり、機能は常にアップデートされています

一般的には使用されません

ラジコン

候補バージョンとして使用され、数回のベータ版を経て比較的安定しており、バグ修正後の正式リリースの準備に使用されます。

テスト使用

M1、M2..

マイルストーン バージョンは通常、大幅な改良が加えられたバージョンです。

あまり使われない

GA、RELEASE、Stable、Final など

実稼働リリース、安定版リリースの場合。

最終用途バージョン

ソースコードのコンパイル

設定項目

ダウンロードしたパッケージを解凍し、次の場所を開きます: spring-framework-5.2.7.RELEASE\gradle\wrapper

765f7e4dab0582b324b9bbdc081fe1b3.png

009f13eec7ae94472ddf6add91767795.png

gradle ラッパーを開く

dcd2e6c8bf23c80c44ed28f70a1083e1.png

構成を変更します: pring-framework-5.2.7.RELEASE の下の build.gradle 新しい構成は次のとおりです。Aliyun ウェアハウスを追加します。

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

Gradle のダウンロードの失敗を避けるために、コード プラグインの下で ID 'io.spring.gradle-enterprise-conventions' バージョン '0.0.2' をシールドします。ebfb8be528d982c5f1bda8bb6b14d6fc.png

コンパイルを入力してください

1.コンパイル

ルート ディレクトリで cmd を開き、次のように実行します。

gradlew :spring-oxm:compileTestJava

結果は次のとおりです。

7cbf47254914606089c0cfba0d297631.png

ヒント: BUILD SUCCESSFUL は成功を意味します。

2. アイデアをインポートしてコンパイルする

アイデアをインポートしてコンパイルします。

cbf7050b97d56eec8b1cdc218bfb423c.png

コンパイルに長時間待つ必要がある(少し長い)

40ffe4e7be4f9e2f2b78b81dff2e4e04.png

ビルドが完了したら

0643071d7504fdf5db31b61d27c8c3d7.png

3. 最後にコードをテストします

新しいモジュール

f1fd6687625d589bf75acb0a2311440a.png

グラドルを選択

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