用途:当用户希望按 COLA 架构组织项目、为各层划分清晰职责、在 COLA 中实践领域驱动设计并保持领域层纯净和依赖倒置、或按 COLA V5 约定组织 Java/Spring Boot 项目时,使用本技能。
主要能力与分层职责:Adapter 处理 I/O;Application 编排用例;Domain 承载业务逻辑;Infrastructure 实现持久化与外部服务。包结构约定:adapter/controller(HTTP/RPC/消息入站处理器)与 adapter/scheduler(定时任务);app/executor(用例执行器,即命令处理器)与 app/service(应用服务,负责编排与事务);domain/model(实体、值对象、聚合,含 entity 与 valueobject)、domain/service(领域服务)、domain/gateway(仓储与外部服务接口,即端口);infrastructure/persistence(仓储实现,如 JPA、MyBatis)、infrastructure/external(外部 API 客户端)、infrastructure/config(Spring 配置与 Bean 装配)。
依赖方向:Adapter → Application → Domain ← Infrastructure。端口定义在 Domain 或 Application,由 Infrastructure 实现;Domain 不依赖任何层,Application 依赖 Domain,Adapter 与 Infrastructure 依赖 Application 和 Domain。
示例要点:领域网关接口 OrderGateway 定义 save 与 findById;应用执行器 CreateOrderExecutor 注入 OrderGateway,在 @Transactional 的 execute 中创建 Order 并保存,返回 OrderDto;基础设施 OrderGatewayImpl 实现该接口并调用 OrderMapper。
最佳实践:业务逻辑仅放在 Domain 层;Application 只做编排和管理事务边界;端口接口定义在 Domain 或 Application,由 Infrastructure 实现;Adapter 层避免业务逻辑,在边界处转换 DTO 与领域对象;遵循 COLA 命名约定,命令用 Cmd、处理器用 Executor、端口用 Gateway。
限制与资源:资料未提供具体安装命令、平台支持范围、收费或性能数据,暂未提供。参考资源包括 COLA GitHub(https://github.com/alibaba/COLA)与 COLA 架构指南(https://blog.csdn.net/significantfrank/article/details/110934799)。