# compents **Repository Path**: cc-projects/compents ## Basic Information - **Project Name**: compents - **Description**: 组件库 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-06-23 - **Last Updated**: 2026-09-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Compents Compents 是一个基于 Spring Boot 3.2.x / JDK 17 开发的自定义组件库,同时支持 Spring Boot 2.7。每个组件遵循官方 Starter 规范,拆分为 **autoconfigure** + **starter** 两个模块,支持按需引入和独立发布。 ## 组件概览 | 组件 | 功能描述 | |------|----------| | **log** | HTTP 请求日志增强,通过拦截器记录请求方法、URI、状态码和耗时,支持路径过滤和慢请求预警 | | **mock** | 接口/方法模拟,支持 HTTP、OpenFeign、RestTemplate 和 Java 方法四级模拟,配备 SpEL 条件匹配和配置中心实时刷新能力 | | **backup** | 同数据源表级数据备份搬运,支持全量/增量备份模式、三种幂等策略、独立事务失败隔离和配置中心实时刷新 | | **encrypt** | 数据库敏感字段透明加密,基于 MyBatis-Plus 拦截器实现写入加密、查询改写和结果解密三阶段处理,支持三阶段渐进迁移和历史数据清洗 | ## 快速开始 ### 引入依赖 在 Maven 项目的 `pom.xml` 中,首先引入 BOM 统一管理版本: ```xml com.cc.compents compents-dependencies 1.0.0-SNAPSHOT pom import ``` 然后按需引入具体组件的 starter: ```xml com.cc.compents compents-log-spring-boot-starter com.cc.compents compents-mock-spring-boot-starter com.cc.compents compents-backup-spring-boot-starter com.cc.compents compents-encrypt-spring-boot-starter ``` ### 配置示例 以下展示各组件的基础配置方式: **log 组件配置示例:** ```yaml compents: log: enabled: true prefix: "[compents-log]" request: enabled: true include-paths: ["/api/**"] exclude-paths: ["/actuator/**", "/favicon.ico"] slow-request-threshold: 1s ``` **backup 组件配置示例:** ```yaml compents: backup: rules: - id: order-archive source-table: t_order target-table: t_order_bak condition: "status = 1" mode: full idempotent-mode: delete-insert order: 0 ``` **encrypt 组件配置示例:** ```yaml compents: encrypt: enabled: true rules: - id: phone-encrypt table: t_user field: phone field-type: plain encrypted-column: phone_enc hash-column: phone_hash phase: dual-write ``` ## 模块结构 ``` compents (pom, 父 POM) ├── compents-dependencies ← BOM:统一管理所有组件版本 ├── compents-log-spring-boot-autoconfigure ← log 组件:自动装配实现 ├── compents-log-spring-boot-starter ← log 组件:空 jar,依赖聚合 ├── compents-mock-spring-boot-autoconfigure ← mock 组件:自动装配实现 ├── compents-mock-spring-boot-starter ← mock 组件:空 jar,依赖聚合 ├── compents-backup-spring-boot-autoconfigure ← backup 组件:自动装配实现 ├── compents-backup-spring-boot-starter ← backup 组件:空 jar,依赖聚合 ├── compents-encrypt-spring-boot-autoconfigure ← encrypt 组件:自动装配实现 ├── compents-encrypt-spring-boot-starter ← encrypt 组件:空 jar,依赖聚合 └── compents-test ← 聚合测试模块 ``` ## 版本兼容 | Spring Boot 版本 | 命名空间 | 制品坐标 | 自动装配机制 | |-----------------|---------|---------|-------------| | 3.x(默认) | jakarta | 默认 | `AutoConfiguration.imports` | | 2.7 | javax | `-Psb27` 构建产物 | `spring.factories` | 构建 2.7 版本制品命令:`mvn clean install -Psb27` ## 构建与测试 ```bash # 构建并跳过测试 mvn clean install -DskipTests # 构建并运行测试(含覆盖率报告) mvn clean install ``` 测试覆盖率报告位置:`compents-test/target/site/jacoco/index.html` 覆盖率要求:compents 包行覆盖率 ≥ 80% ## 文档导航 | 文档 | 面向对象 | 内容 | |------|----------|------| | **[ARCHITECTURE.md](ARCHITECTURE.md)** | 维护者/贡献者 | 架构设计模式、级联装配、热刷新、异常传播等 | | **[CONTRIBUTING.md](CONTRIBUTING.md)** | 贡献者 | 新增组件流程、自动装配规范、测试规范 | | **[compents-log-spring-boot-autoconfigure README](compents-log-spring-boot-autoconfigure/README.md)** | 使用方 | 请求日志增强详细用法 | | **[compents-mock-spring-boot-autoconfigure README](compents-mock-spring-boot-autoconfigure/README.md)** | 使用方 | 接口/方法模拟详细用法 | | **[compents-backup-spring-boot-autoconfigure README](compents-backup-spring-boot-autoconfigure/README.md)** | 使用方 | 数据备份搬运详细用法 | | **[compents-encrypt-spring-boot-autoconfigure README](compents-encrypt-spring-boot-autoconfigure/README.md)** | 使用方 | 敏感字段加密详细用法 |