Verifying Application Module Structure

  • 仅允许明确定义的应用模块依赖关系(可选)。

  • 可选择与 ArchUnit 集成,以自动执行特定于域驱动设计的验证规则。

我们可以通过调用`ApplicationModules`实例上的`….verify()`方法来验证我们的代码排列是否符合预期的约束:

We can verify whether our code arrangement adheres to the intended constraints by calling the ….verify() method on our ApplicationModules instance:

  • Java

  • Kotlin

ApplicationModules.of(Application.class).verify();
ApplicationModules.of(Application::class).verify()

验证包括以下规则:

The verification includes the following rules:

  • No cycles on the application module level - 模块之间的依赖关系必须形成有向无环图。

  • No cycles on the application module level — the dependencies between modules have to form directed, acyclic graph.

  • Efferent module access via API packages only - 所有引用内部应用程序模块包中类型的引用都会被拒绝。请参阅 Advanced Application Modules 了解详情。

  • Efferent module access via API packages only — All references to types that reside in application module internal packages are rejected. See Advanced Application Modules for details.

  • Explicitly allowed application module dependencies only (可选) - 应用程序模块可以选择通过 @ApplicationModule(allowedDependencies = …) 定义允许的依赖项。如果配置了这些依赖项,则会拒绝对其他应用程序模块的依赖项。请参阅 Explicit Application Module DependenciesNamed Interfaces 了解详情。

  • Explicitly allowed application module dependencies only (optional) — An application module can optionally define allowed dependencies via @ApplicationModule(allowedDependencies = …). If those are configured, dependencies to other application modules are rejected. See Explicit Application Module Dependencies and Named Interfaces for details.

Spring Modulith 可选择与 jMolecules ArchUnit 库集成,并在存在时自动触发其描述的 here 的领域驱动设计验证规则。

Spring Modulith optionally integrates with the jMolecules ArchUnit library and, if present, automatically triggers its Domain-Driven Design verification rules described here.