此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Modulith 1.4.3! |
生产就绪功能
如果要将自定义应用于此处所述的应用程序模块检测,则需要将它们移动到生产源中(除非已存在),以确保此处描述的功能会考虑这些自定义项。 |
Spring Modulith 支持将有关系统的架构信息公开为 Spring Boot 执行器端点,并通过捕获指标和跟踪来观察应用程序模块之间的交互。 由于生产就绪的应用程序可能需要两者,因此激活这些功能的最便捷方法是使用 Spring Modulith Insight Starters,如下所示:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-starter-insight</artifactId>
<version>1.3.10-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-starter-insight:1.3.10-SNAPSHOT'
}
这将包括执行器和可观察性支持,以及 Spring Boot 的执行器启动,以提供对执行器的一般支持。 请注意,您仍然需要添加更多依赖项才能将应用程序连接到监控工具,例如 Zipkin、Wavefront 等,通常通过 OpenTelemetry 或 Brave。 在 Spring Boot 参考文档的相应部分中找到更多信息。
应用模块执行器
应用程序模块结构可以公开为 Spring Boot 执行器。
要启用执行器,请添加spring-modulith-actuator
对项目的依赖:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-actuator</artifactId>
<version>1.3.10-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<!-- Spring Boot actuator starter required to enable actuators in general -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>…</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-actuator:1.3.10-SNAPSHOT'
}
<!-- Spring Boot actuator starter required to enable actuators in general -->
dependencies {
runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
}
运行应用程序现在将公开一个modulith
执行器资源:
GET http://localhost:8080/actuator
{
"_links": {
"self": {
"href": "http://localhost:8080/actuator",
"templated": false
},
"health-path": {
"href": "http://localhost:8080/actuator/health/{*path}",
"templated": true
},
"health": {
"href": "http://localhost:8080/actuator/health",
"templated": false
},
"modulith": { (1)
"href": "http://localhost:8080/actuator/modulith",
"templated": false
}
}
}
1 | 这modulith 执行器资源广告。 |
这modulith
资源遵循以下结构:
JSONPath | 描述 |
---|---|
|
应用程序模块的技术名称。模块引用的目标 |
|
应用程序模块的人类可读名称。 |
|
应用程序模块的基本包。 |
|
应用程序模块的所有传出依赖项 |
|
所依赖的应用程序模块的名称。对 |
|
目标模块的依赖类型。可以是 |
示例模块排列如下所示:
{
"a": {
"basePackage": "example.a",
"displayName": "A",
"dependencies": []
},
"b": {
"basePackage": "example.b",
"displayName": "B",
"dependencies": [ {
"target": "a",
"types": [ "EVENT_LISTENER", "USES_COMPONENT" ]
} ]
}
}
观察应用程序模块
可以拦截应用程序模块之间的交互以创建微米跨度,最终形成您可以在 Zipkin 等工具中可视化的轨迹。 要激活检测,请将以下运行时依赖项添加到您的项目:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-observability</artifactId>
<version>1.3.10-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-observability:1.3.10-SNAPSHOT'
}
您必须根据要通过管道将可观测性元数据引入的工具配置其他基础架构依赖项。 有关详细信息,请查看相应的 Spring Boot 文档,了解您的设置中要包含哪些依赖项。 |
这将导致作为应用程序模块 API 一部分的所有 Spring 组件都被装饰为一个方面,该方面将拦截调用并为它们创建微米跨度。 示例调用跟踪如下所示:

在这种特殊情况下,触发付款会更改订单的状态,从而导致触发订单完成事件。 这被引擎异步拾取,引擎触发订单上的另一个状态更改,工作几秒钟,然后依次触发订单上的最终状态更改。