Spring Modulith 支持将有关系统的架构信息公开为 Spring Boot 执行器端点,并通过捕获指标和跟踪来观察应用程序模块之间的交互。 由于生产就绪型应用程序可能需要这两者,因此激活这些功能的最便捷方法是使用 Spring Modulith Insight 启动器,如下所示:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-starter-insight</artifactId>
<version>1.2.1</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-starter-insight:1.2.1'
}
这将包括执行器和可观测性支持,以及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.2.1</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.2.1'
}
<!-- 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 | 描述 |
---|---|
|
应用程序模块的技术名称。中模块引用的目标。 |
|
应用程序模块的人类可读名称。 |
|
应用程序模块的基础包。 |
|
应用程序模块的所有传出依赖项 |
|
应用程序模块的名称取决于。对 . |
|
对目标模块的依赖项类型。可以是 (简单类型依赖项)、(Spring Bean 依赖项)或 . |
示例模块排列如下所示:
{
"a": {
"basePackage": "example.a",
"displayName": "A",
"dependencies": []
},
"b": {
"basePackage": "example.b",
"displayName": "B",
"dependencies": [ {
"target": "a",
"types": [ "EVENT_LISTENER", "USES_COMPONENT" ]
} ]
}
}
1 | 执行器资源播发。modulith |
JSONPath | 描述 |
---|---|
|
应用程序模块的技术名称。中模块引用的目标。 |
|
应用程序模块的人类可读名称。 |
|
应用程序模块的基础包。 |
|
应用程序模块的所有传出依赖项 |
|
应用程序模块的名称取决于。对 . |
|
对目标模块的依赖项类型。可以是 (简单类型依赖项)、(Spring Bean 依赖项)或 . |
观察应用模块
可以截获应用程序模块之间的交互以创建千分尺跨度,最终形成可以在 Zipkin 等工具中可视化的轨迹。 若要激活检测,请将以下运行时依赖项添加到项目中:
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.modulith</groupId>
<artifactId>spring-modulith-observability</artifactId>
<version>1.2.1</version>
<scope>runtime</scope>
</dependency>
dependencies {
runtimeOnly 'org.springframework.modulith:spring-modulith-observability:1.2.1'
}
您必须配置其他基础结构依赖项,具体取决于要通过管道传输可观测性元数据的工具。 有关详细信息,请查看相应的 Spring Boot 文档,了解您的设置要包含哪些依赖项。 |
这将导致作为应用程序模块 API 一部分的所有 Spring 组件都使用一个方面进行修饰,该方面将拦截调用并为它们创建微米跨度。 调用跟踪示例如下所示:

在这种特殊情况下,触发付款会改变订单的状态,从而导致触发订单完成事件。 这被引擎异步拾取,触发订单上的另一个状态更改,工作几秒钟,然后依次触发订单上的最终状态更改。
您必须配置其他基础结构依赖项,具体取决于要通过管道传输可观测性元数据的工具。 有关详细信息,请查看相应的 Spring Boot 文档,了解您的设置要包含哪些依赖项。 |