通过创建的应用程序模块模型可用于创建文档片段,以包含在用 Asciidoc 编写的开发人员文档中。 Spring Modolith 的抽象可以生成两种不同类型的片段:ApplicationModulesDocumenter

  • 描述各个应用程序模块之间关系的 C4 和 UML 组件图

  • 所谓的应用程序模块画布,关于模块和其中最相关的元素(Spring Bean、聚合根、发布和侦听的事件以及配置属性)的表格概述。

生成应用程序模块组件图

可以通过将实例交给 .ApplicationModulesDocumenter

使用Documenter
  • Java

  • Kotlin

class DocumentationTests {

  ApplicationModules modules = ApplicationModules.of(Application.class);

  @Test
  void writeDocumentationSnippets() {

    new Documenter(modules)
      .writeModulesAsPlantUml()
      .writeIndividualModulesAsPlantUml();
  }
}
class DocumentationTests {
    private val modules = ApplicationModules.of(Application::class)

    @Test
    fun writeDocumentationSnippets() {
        Documenter(modules)
            .writeModulesAsPlantUml()
            .writeIndividualModulesAsPlantUml()
    }
}

第一次调用将生成包含系统内所有模块的 C4 组件图。Documenter

所有模块及其关系呈现为 C4 组件图
图 1.所有模块及其关系呈现为 C4 组件图

第二次调用将创建其他关系图,这些关系图仅包括单个模块及其在画布上直接依赖的模块。

应用程序模块的子集及其关系从呈现为 C4 组件图的顺序模块开始
图2.应用程序模块的子集及其关系从呈现为 C4 组件图的顺序模块开始

使用传统的 UML 组件图

如果您更喜欢传统的 UML 样式组件图,请调整为使用该样式,如下所示:DiagramOptions

  • Java

  • Kotlin

DiagramOptions.defaults()
  .withStyle(DiagramStyle.UML);
DiagramOptions.defaults()
  .withStyle(DiagramStyle.UML)

这将导致关系图如下所示:

所有模块及其关系呈现为 UML 组件图
图3.所有模块及其关系呈现为 UML 组件图
应用程序模块的子集及其关系,从呈现为 UML 组件图的顺序模块开始
图4.应用程序模块的子集及其关系,从呈现为 UML 组件图的顺序模块开始

生成应用程序模块画布

应用程序模块画布可以通过调用来生成:Documenter.writeModuleCanvases()

使用Documenter
  • Java

  • Kotlin

class DocumentationTests {

  ApplicationModules modules = ApplicationModules.of(Application.class);

  @Test
  void writeDocumentationSnippets() {

    new Documenter(modules)
      .writeModuleCanvases();
  }
}
class DocumentationTests {

  private val modules = ApplicationModules.of(Application::class)

  @Test
  fun writeDocumentationSnippets() {
    Documenter(modules)
        .writeModuleCanvases()
  }
}

默认情况下,文档将生成到构建系统的构建文件夹中的文件夹中。 生成的画布如下所示:spring-modulith-docs

表 1.应用程序模块画布示例

基础包

com.acme.commerce.inventory

弹簧组件

服务业

  • c.a.c.i.InventoryManagement

存储 库

  • c.a.c.i.Inventory

事件侦听器

  • c.a.c.i.InternalInventoryListeners听 ,o.s.m.m.DayHasPassedc.a.c.i.QuantityReduced

  • c.a.c.i.InventoryOrderEventListener听 ,c.a.c.o.OrderCanceledc.a.c.o.OrderCompleted

配置属性

  • c.a.c.i.InventoryProperties

别人

  • c.a.c.i.InventoryItemCreationListener

聚合根

  • c.a.c.i.InventoryItem

已发布的事件

  • c.a.c.i.QuantityReduced创建者:

    • c.a.c.i.InventoryItem.decreaseQuantity(…)

  • c.a.c.i.StockShort创建者:

    • c.a.c.i.InternalInventoryListeners.on(…)

收听的活动

  • c.a.c.o.OrderCompleted

  • c.a.c.o.OrderCanceled

性能

  • acme.commerce.inventory.restock-threshold— .在库存更新期间应触发 a 的阈值。c.a.c.c.QuantityInventoryEvents.StockShort

它由以下部分组成:

  • 应用程序模块的基础包。

  • 应用程序模块公开的 Spring Bean,按构造型分组。— 换言之,位于 API 包或任何命名接口包中的 Bean。 这将检测由 jMolecules 架构抽象定义的组件构造,以及标准的 Spring 构造构造注释。

  • 暴露的聚合根 — 我们找到存储库或通过 jMolecules 明确声明为聚合的任何实体。

  • 模块发布的应用程序事件 — 这些事件类型需要使用 jMolecules 进行划分或实现其接口。@DomainEventDomainEvent

  • 模块侦听的应用程序事件 — 派生自 Spring 的 、 、 jMolecules 或 beans 实现 注释的方法。@EventListener@TransactionalEventListener@DomainEventHandlerApplicationListener

  • 配置属性 — 应用程序模块公开的 Spring Boot 配置属性。 需要使用项目来提取附加到属性的元数据。spring-boot-configuration-processor

表 1.应用程序模块画布示例

基础包

com.acme.commerce.inventory

弹簧组件

服务业

  • c.a.c.i.InventoryManagement

存储 库

  • c.a.c.i.Inventory

事件侦听器

  • c.a.c.i.InternalInventoryListeners听 ,o.s.m.m.DayHasPassedc.a.c.i.QuantityReduced

  • c.a.c.i.InventoryOrderEventListener听 ,c.a.c.o.OrderCanceledc.a.c.o.OrderCompleted

配置属性

  • c.a.c.i.InventoryProperties

别人

  • c.a.c.i.InventoryItemCreationListener

聚合根

  • c.a.c.i.InventoryItem

已发布的事件

  • c.a.c.i.QuantityReduced创建者:

    • c.a.c.i.InventoryItem.decreaseQuantity(…)

  • c.a.c.i.StockShort创建者:

    • c.a.c.i.InternalInventoryListeners.on(…)

收听的活动

  • c.a.c.o.OrderCompleted

  • c.a.c.o.OrderCanceled

性能

  • acme.commerce.inventory.restock-threshold— .在库存更新期间应触发 a 的阈值。c.a.c.c.QuantityInventoryEvents.StockShort