目次
spring5.x アーキテクチャ
データ アクセス/統合:データ アクセス/統合モジュール: 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
注: git が遅い場合は、手動でダウンロードできます。
バージョン紹介
名前 |
説明 |
述べる |
アルファ |
内部テスト版のため、バグが多く、不安定で、常に更新されています |
一般的には使用されません |
ベータ1、ベータ2... |
パブリックベータ版はアルファ版に比べて不安定であり、機能は常にアップデートされています |
一般的には使用されません |
ラジコン |
候補バージョンとして使用され、数回のベータ版を経て比較的安定しており、バグ修正後の正式リリースの準備に使用されます。 |
テスト使用 |
M1、M2.. |
マイルストーン バージョンは通常、大幅な改良が加えられたバージョンです。 |
あまり使われない |
GA、RELEASE、Stable、Final など |
実稼働リリース、安定版リリースの場合。 |
最終用途バージョン |
ソースコードのコンパイル
設定項目
ダウンロードしたパッケージを解凍し、次の場所を開きます: spring-framework-5.2.7.RELEASE\gradle\wrapper
gradle ラッパーを開く
構成を変更します: 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' をシールドします。
コンパイルを入力してください
1.コンパイル
ルート ディレクトリで cmd を開き、次のように実行します。
gradlew :spring-oxm:compileTestJava
結果は次のとおりです。
ヒント: BUILD SUCCESSFUL は成功を意味します。
2. アイデアをインポートしてコンパイルする
アイデアをインポートしてコンパイルします。
コンパイルに長時間待つ必要がある(少し長い)
ビルドが完了したら
3. 最後にコードをテストします
新しいモジュール
グラドルを選択
カスタムモジュール名を入力します
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