对于最新的稳定版本,请使用 Spring Modulith 1.2.1Spring中文文档

对于最新的稳定版本,请使用 Spring Modulith 1.2.1Spring中文文档

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

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

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

生成应用程序模块组件图

可以通过将实例交给 .ApplicationModulesDocumenterSpring中文文档

使用Documenter
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 组件图。DocumenterSpring中文文档

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

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

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

使用传统的 UML 组件图

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

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

这将导致关系图如下所示:Spring中文文档

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

生成应用程序模块画布

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

使用Documenter
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-docsSpring中文文档

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

基础包Spring中文文档

com.acme.commerce.inventorySpring中文文档

弹簧组件Spring中文文档

存储 库Spring中文文档

事件侦听器Spring中文文档

  • c.a.c.i.InternalInventoryListeners听 ,o.s.m.m.DayHasPassedc.a.c.i.QuantityReducedSpring中文文档

  • c.a.c.i.InventoryOrderEventListener听 ,c.a.c.o.OrderCanceledc.a.c.o.OrderCompletedSpring中文文档

配置属性Spring中文文档

聚合根Spring中文文档

已发布的事件Spring中文文档

收听的活动Spring中文文档

性能Spring中文文档

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

它由以下部分组成:Spring中文文档

  • 应用程序模块的基础包。Spring中文文档

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

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

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

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

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

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

基础包Spring中文文档

com.acme.commerce.inventorySpring中文文档

弹簧组件Spring中文文档

存储 库Spring中文文档

事件侦听器Spring中文文档

  • c.a.c.i.InternalInventoryListeners听 ,o.s.m.m.DayHasPassedc.a.c.i.QuantityReducedSpring中文文档

  • c.a.c.i.InventoryOrderEventListener听 ,c.a.c.o.OrderCanceledc.a.c.o.OrderCompletedSpring中文文档

配置属性Spring中文文档

聚合根Spring中文文档

已发布的事件Spring中文文档

收听的活动Spring中文文档

性能Spring中文文档

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