用 ai-native-service / auto-layout-service 的 common、client、web 模块,读懂工程边界、依赖来源和 Java 8/21 混合模块
测试转开发读后端工程时,第一步不是找某个类,而是打开根目录的 pom.xml。它告诉你三件事:这是一个父工程、下面有哪些子模块、版本大多从哪里来。
<packaging>pom</packaging> 通常表示“聚合父工程”,不是直接启动的业务包。真正启动服务的,通常在 *-web 模块里。
ai-native-service / auto-layout-service ├── pom.xml 父工程:声明 modules、父依赖、统一版本 ├── *-common / pom.xml 共享 DTO / VO / 枚举 / 契约模型 ├── *-client / pom.xml 给别的服务调用自己的客户端包 └── *-web / pom.xml Controller / Service / Manager / Mapper,启动入口
两个仓库都是真实的三模块结构:
| 仓库 | 父 artifactId | modules | 启动模块 |
|---|---|---|---|
ai-native-service | ai-native-service-parent | ai-native-service-commonai-native-service-clientai-native-service-web | ai-native-service-web |
auto-layout-service | auto-layout-service-parent | auto-layout-service-commonauto-layout-service-clientauto-layout-service-web | auto-layout-service-web |
你可以先用“谁会依赖谁”来判断边界:
| 模块 | 主要内容 | AIHom 读代码时怎么用 |
|---|---|---|
common | 请求 / 响应 VO、DTO、枚举、校验注解等共享对象 | 看到接口入参或返回值,先到这里找字段含义 |
client | 给其他服务使用的调用封装,例如 AiNativeClient | 跨服务调用时,先看 client 暴露了哪些方法 |
web | Controller、Service、Factory、Manager、Mapper、配置和启动类 | 新增功能大多数改这里;排查问题也从这里追调用链 |
auto-layout-service-web 依赖了 ai-native-service-client,代码里 AiNativeManager 注入 AiNativeClient,再调用 imageGenerateWithPolling。这说明 client 是“跨服务调用的门面”。
Maven 查版本时,不要只看当前模块。顺序通常是:
<dependency> 自己写了 <version>,就用它。<dependencyManagement> 找。pilot-boot-dependencies。type=pom + scope=import 导入一整套版本。<dependencyManagement> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-bom</artifactId> <version>${spring-ai.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencyManagement>
ai-native-service 的父 POM 里能看到 spring-ai.version、spring-ai-alibaba.version、netty.version、mybatis-plus.version 这些集中版本。ai-native-service-web 里再使用 spring-ai-openai、spring-ai-starter-mcp-client 等依赖时,就不一定需要逐个写版本。
课程里不要把“没写 version”理解成“没有版本”。很多版本被父 POM 或 BOM 管住了。测试定位依赖冲突时,要顺着父子 POM 往上找。
ai-native-service 父工程声明 java.version=21,但 ai-native-service-common 和 ai-native-service-client 都用 maven-compiler-plugin 的 <release>8</release>。这不是矛盾,而是边界设计。
| 位置 | Java 版本信号 | 意思 |
|---|---|---|
ai-native-service/pom.xml | java.version=21 | web 服务主工程可以使用 Java 21 / Spring Boot 3 生态 |
ai-native-service-common/pom.xml | release 8 | 共享模型尽量兼容老服务 |
ai-native-service-client/pom.xml | release 8 | 客户端包要给 Java 8 服务依赖,比如 auto-layout-service |
auto-layout-service/pom.xml | java.version=1.8 | 自动布局服务整体还是 Java 8 风格 |
所以读代码时要形成一个直觉:common / client 是契约边界,通常更保守;web 是业务运行边界,版本可能更新。
pom.xml,确认 packaging、modules、父依赖。*-web/pom.xml,找 spring-boot-maven-plugin 的 mainClass。*-web 依赖了哪些 common、client 和外部 SDK。common 或 web/.../vo 找字段。| 你要确认什么 | 真实文件 |
|---|---|
| 两个服务都有 common/client/web 三模块 | ai-native-service/pom.xmlauto-layout-service/pom.xml |
ai-native-service 父工程 Java 21、Spring AI BOM | ai-native-service/pom.xml |
ai-native-service-common / client 编译 Java 8 | ai-native-service/ai-native-service-common/pom.xmlai-native-service/ai-native-service-client/pom.xml |
auto-layout-service Java 8,web 依赖 ai-native-service-client | auto-layout-service/pom.xmlauto-layout-service/auto-layout-service-web/pom.xml |
| 跨服务 client 真实调用 | AiNativeClientAiNativeManager |
<packaging>pom</packaging> 最像在说什么?想补 Maven 基础,优先看 Apache Maven 官方的 Introduction to the POM。读完这节课后,只需要重点理解 parent、modules、dependencyManagement、properties。