附錄

附錄 A: Spring Boot 相容性

Spring Modulith 版本 Spring Boot 版本
(編譯依賴版本)
Spring Boot 版本
(示例測試依賴版本)
jMolecules
(編譯)
jMolecules
(測試)

1.4 (snapshot)

3.4

3.1, 3.2, 3.3, 3.4

2023.2

2023.2, 2025.0 RC2

1.3

3.4

3.1, 3.2, 3.3, 3.4

2023.1

2023.1, 2023.2, 2025.0 RC2

1.2

3.3

3.1, 3.2, 3.3, 3.4

2023.1

2023.1, 2023.2, 2025.0 RC2

1.1

3.2

3.1, 3.2, 3.3, 3.4

2023.1

2023.1, 2023.2, 2025.0 RC2

附錄 B: Spring Modulith 配置屬性

屬性 預設值 描述

spring.modulith.default-async-termination

true

是否為非同步處理終止配置預設值,即等待任務完成 2 秒鐘。詳情請參閱 TaskExecutionProperties

spring.modulith.detection-strategy

none

應用於檢測應用模組的策略。可以是自定義 ApplicationModuleDetectionStrategy 實現的類名,或者 direct-subpackages(未配置任何內容時的最終回退),或者 explicitly-annotated(僅選擇使用 @ApplicationModule 或 jMolecules 的 @Module 顯式註解的包)。詳情請參閱自定義應用模組檢測

spring.modulith.events.completion-mode

update

如何將事件釋出標記為已完成。支援以下值:

  • update (預設) — 在事件釋出條目上設定完成日期。

  • delete — 移除事件釋出條目。已完成的事件釋出無法透過 CompletedEventPublications 獲取。

  • archive — 從主資料庫抽象(表、集合或節點)中移除事件釋出條目,並在歸檔中建立一份(同模式的表、集合或節點)。詳情請參閱事件釋出完成

spring.modulith.events.externalization.enabled

true

是否啟用事件外部化。

spring.modulith.events.jdbc.schema-initialization.enabled

false

是否初始化 JDBC 事件釋出模式。

spring.modulith.events.jdbc.schema

事件釋出表的模式名稱。如果未指定,該表將不使用模式限定。

spring.modulith.events.kafka.enable-json

true

是否為 KafkaTemplate 啟用 JSON 支援。

spring.modulith.events.mongodb.transaction-management.enabled

true

是否自動為 MongoDB 啟用事務。需要資料庫以副本集模式執行。

spring.modulith.events.neo4j.event-index.enabled

false

是否在 Neo4j 事件釋出的事件雜湊屬性上建立索引。

spring.modulith.events.rabbitmq.enable-json

true

是否為 RabbitTemplate 啟用 JSON 支援。

spring.modulith.events.republish-outstanding-events-on-restart

false

是否在應用程式重啟時重新發布未完成的事件。在多例項部署中通常不推薦此操作,因為其他例項可能仍在處理事件。

spring.modulith.moments.enableTimeMachine

false

是否啟用TimeMachine

spring.modulith.moments.granularity

HOURS

釋出事件的粒度。(HOURS, DAYS)

spring.modulith.moments.locale

Locale.getDefault()

確定周邊界時使用的 Locale

spring.modulith.moments.zoneId

ZoneOffset.UTC

釋出事件日期所在的時區。

spring.modulith.republish-outstanding-events-on-restart

false

自 1.3 版本起已棄用。請優先使用 spring.modulith.events.republish-outstanding-events-on-restart

spring.modulith.test.file-modification-detector

none

這可以是預定義值之一:uncommitted-changesreference-commitdefault,或是一個用於檢查專案哪些檔案已被修改的 FileModificationDetector 的完全限定類名。正如其名稱所示,uncommitted-changes 只會考慮尚未提交的更改檔案。reference-commit 會考慮自透過 spring.modulith.test.reference-commit 提供的給定 Git 提交以來所有更改的檔案,這在 CI 環境中特別有用,該屬性可以指向上次成功構建的提交雜湊值。default 會檢測所有未提交的更改以及尚未推送到當前分支跟蹤分支的更改,這主要適用於本地開發。

spring.modulith.test.reference-commit

none

用於計算更改檔案集的提交雜湊值。通常在 CI 環境中傳播,以考慮自上次成功構建以來的所有更改。

附錄 C: Spring Modulith 模組

表 1. Spring Modulith Starter POM
Starter 典型作用域 包含

spring-modulith-starter-core

compile

  • spring-modulith-api

  • spring-modulith-apt

  • spring-modulith-moments

  • spring-modulith-core (runtime)

  • spring-modulith-runtime (runtime)

spring-modulith-starter-insight

runtime

  • spring-modulith-actuator (runtime)

  • spring-modulith-observability (runtime)

  • spring-boot-starter-actuator (runtime)

spring-modulith-starter-jdbc

compile

  • spring-modulith-starter-core

  • spring-modulith-events-api

  • spring-modulith-events-core (runtime)

  • spring-modulith-events-jdbc (runtime)

  • spring-modulith-events-jackson (runtime)

spring-modulith-starter-jpa

compile

  • spring-modulith-starter-core

  • spring-modulith-events-api

  • spring-modulith-events-core (runtime)

  • spring-modulith-events-jpa (runtime)

  • spring-modulith-events-jackson (runtime)

spring-modulith-starter-mongodb

compile

  • spring-modulith-starter-core

  • spring-modulith-events-api

  • spring-modulith-events-core (runtime)

  • spring-modulith-events-mongodb (runtime)

  • spring-modulith-events-jackson (runtime)

spring-modulith-starter-neo4j

compile

  • spring-modulith-starter-core

  • spring-modulith-events-api

  • spring-modulith-events-core (runtime)

  • spring-modulith-events-neo4j (runtime)

  • spring-modulith-events-jackson (runtime)

spring-modulith-starter-test

test

  • spring-modulith-docs

  • spring-modulith-test

表 2. 各個 Spring Modulith JAR
模組 典型作用域 描述

spring-modulith-actuator

runtime

一個 Spring Boot Actuator,用於透過 Actuator 暴露應用模組結構。

spring-modulith-api

compile

在生產程式碼中用於定製 Spring Modulith 預設行為的抽象。

spring-modulith-apt

compile

一個註解處理器,用於提取 Javadoc 以包含在應用模組 Canvas 中。

spring-modulith-core

runtime

核心應用模組模型和 API。

spring-modulith-docs

test

Documenter API,用於從模組模型建立 Asciidoctor 和 PlantUML 文件。

spring-modulith-events-amqp

runtime

對 AMQP 的事件外部化支援。

spring-modulith-events-api

runtime

用於定製 Spring Modulith 事件特性的 API。

spring-modulith-events-core

runtime

事件釋出登錄檔的核心實現以及整合抽象 EventPublicationRegistryEventPublicationSerializer

spring-modulith-events-jackson

runtime

基於 Jackson 的 EventPublicationSerializer 實現。

spring-modulith-events-jdbc

runtime

基於 JDBC 的 EventPublicationRegistry 實現。

spring-modulith-events-jms

runtime

對 JMS 的事件外部化支援。

spring-modulith-events-jpa

runtime

基於 JPA 的 EventPublicationRegistry 實現。

spring-modulith-events-kafka

runtime

對 Kafka 的事件外部化支援。

spring-modulith-events-messaging

runtime

將事件外部化到 Spring Messaging MessageChannel 的支援。

spring-modulith-events-mongodb

runtime

基於 MongoDB 的 EventPublicationRegistry 實現。

spring-modulith-events-neo4j

runtime

基於 Neo4j 的 EventPublicationRegistry 實現。

spring-modulith-junit

test

基於應用模組結構的測試執行最佳化。詳情請參閱此處

spring-modulith-moments

compile

此處描述的時間流逝事件實現。

spring-modulith-observability

runtime

此處描述的可觀測性基礎設施。

spring-modulith-runtime

runtime

支援在執行時引導 ApplicationModules 例項。通常不直接依賴,而是由 spring-modulith-actuatorspring-modulith-observability 傳遞依賴。

spring-modulith-test

test

整合測試支援。詳情請參閱此處

附錄 D: 已棄用模組

表 3. 已棄用模組表
模組 棄用版本 描述

spring-modulith-events-aws-sns

1.3

請遷移到 io.awspring.cloud:spring-cloud-aws-modulith-events-sns。詳情請參閱此連結

spring-modulith-events-aws-sqs

1.3

請遷移到 io.awspring.cloud:spring-cloud-aws-modulith-events-sqs。詳情請參閱此連結

附錄 E: 事件釋出登錄檔模式

基於 JDBC 的事件釋出登錄檔支援要求資料庫中存在以下資料庫模式。如果您希望 Spring Modulith 為您建立模式,請將應用屬性 spring.modulith.events.jdbc-schema-initialization.enabled 設定為 true

H2

CREATE TABLE IF NOT EXISTS EVENT_PUBLICATION
(
  ID               UUID NOT NULL,
  COMPLETION_DATE  TIMESTAMP(9) WITH TIME ZONE,
  EVENT_TYPE       VARCHAR(512) NOT NULL,
  LISTENER_ID      VARCHAR(512) NOT NULL,
  PUBLICATION_DATE TIMESTAMP(9) WITH TIME ZONE NOT NULL,
  SERIALIZED_EVENT VARCHAR(4000) NOT NULL,
  PRIMARY KEY (ID)
);
CREATE INDEX IF NOT EXISTS EVENT_PUBLICATION_BY_LISTENER_ID_AND_SERIALIZED_EVENT_IDX ON EVENT_PUBLICATION (LISTENER_ID, SERIALIZED_EVENT);
CREATE INDEX IF NOT EXISTS EVENT_PUBLICATION_BY_COMPLETION_DATE_IDX ON EVENT_PUBLICATION (COMPLETION_DATE);

HSQLDB

CREATE TABLE IF NOT EXISTS EVENT_PUBLICATION
(
  ID               UUID NOT NULL,
  COMPLETION_DATE  TIMESTAMP(9),
  EVENT_TYPE       VARCHAR(512) NOT NULL,
  LISTENER_ID      VARCHAR(512) NOT NULL,
  PUBLICATION_DATE TIMESTAMP(9) NOT NULL,
  SERIALIZED_EVENT VARCHAR(4000) NOT NULL,
  PRIMARY KEY (ID)
);
CREATE INDEX IF NOT EXISTS EVENT_PUBLICATION_BY_LISTENER_ID_AND_SERIALIZED_EVENT_IDX ON EVENT_PUBLICATION (LISTENER_ID, SERIALIZED_EVENT);
CREATE INDEX IF NOT EXISTS EVENT_PUBLICATION_BY_COMPLETION_DATE_IDX ON EVENT_PUBLICATION (COMPLETION_DATE);

MariaDB

CREATE TABLE IF NOT EXISTS EVENT_PUBLICATION
(
  ID               VARCHAR(36) NOT NULL,
  LISTENER_ID      VARCHAR(512) NOT NULL,
  EVENT_TYPE       VARCHAR(512) NOT NULL,
  SERIALIZED_EVENT VARCHAR(4000) NOT NULL,
  PUBLICATION_DATE TIMESTAMP(6) NOT NULL,
  COMPLETION_DATE  TIMESTAMP(6) DEFAULT NULL NULL,
  PRIMARY KEY (ID),
  INDEX EVENT_PUBLICATION_BY_COMPLETION_DATE_IDX (COMPLETION_DATE)
);

Microsoft SQL Server

IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'EVENT_PUBLICATION')
CREATE TABLE EVENT_PUBLICATION
(
  ID               VARCHAR(36) NOT NULL,
  LISTENER_ID      VARCHAR(512) NOT NULL,
  EVENT_TYPE       VARCHAR(512) NOT NULL,
  SERIALIZED_EVENT VARCHAR(MAX) NOT NULL,
  PUBLICATION_DATE DATETIME2(6) NOT NULL,
  COMPLETION_DATE  DATETIME2(6) NULL,
  PRIMARY KEY (ID),
  INDEX EVENT_PUBLICATION_BY_COMPLETION_DATE_IDX (COMPLETION_DATE)
);

MySQL

CREATE TABLE IF NOT EXISTS EVENT_PUBLICATION
(
  ID               VARCHAR(36) NOT NULL,
  LISTENER_ID      VARCHAR(512) NOT NULL,
  EVENT_TYPE       VARCHAR(512) NOT NULL,
  SERIALIZED_EVENT VARCHAR(4000) NOT NULL,
  PUBLICATION_DATE TIMESTAMP(6) NOT NULL,
  COMPLETION_DATE  TIMESTAMP(6) DEFAULT NULL NULL,
  PRIMARY KEY (ID),
  INDEX EVENT_PUBLICATION_BY_COMPLETION_DATE_IDX (COMPLETION_DATE)
);

PostgreSQL

CREATE TABLE IF NOT EXISTS event_publication
(
  id               UUID NOT NULL,
  listener_id      TEXT NOT NULL,
  event_type       TEXT NOT NULL,
  serialized_event TEXT NOT NULL,
  publication_date TIMESTAMP WITH TIME ZONE NOT NULL,
  completion_date  TIMESTAMP WITH TIME ZONE,
  PRIMARY KEY (id)
);
CREATE INDEX IF NOT EXISTS event_publication_serialized_event_hash_idx ON event_publication USING hash(serialized_event);
CREATE INDEX IF NOT EXISTS event_publication_by_completion_date_idx ON event_publication (completion_date);

附錄 F: 從 Moduliths 遷移

  • o.m.model.Modules 已重新命名為 o.s.m.model.ApplicationModules

  • o.m.model.ModuleDetectionStrategy 已重新命名為 o.s.m.model.ApplicationModuleDetectionStrategy

  • @o.m.test.ModuleTest 已重新命名為 @o.s.m.test.ApplicationModuleTest

  • o.m.docs.Documenter.Options 已重新命名為 o.s.m.docs.Documenter.DiagramOptions

  • 元件圖的圖表樣式現在預設為 DiagramStyle.C4(透過呼叫 DiagramOptions.withStyle(DiagramStyle.UML) 覆蓋)

  • 模組 canvas 預設隱藏非暴露型別。要在 canvas 中包含應用模組內部型別,請將 CanvasOptions 配置為 ….revealInternals()

  • 元件圖和應用模組 canvas 的輸出資料夾已從 moduliths-docs 移動到構建目標資料夾(例如 Maven 的 target)中的 spring-modulith-docs