209 lines
8.7 KiB
Markdown
209 lines
8.7 KiB
Markdown
# LMS 模块 application.yaml 配置说明
|
||
|
||
## 一、Spring 基础配置
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `spring.application.name` | `lms-server` | 服务名称,用于 Nacos 注册中心和日志文件命名 |
|
||
| `spring.profiles.active` | `dev` | 激活的 profile,决定加载 `application-dev.yaml` |
|
||
| `spring.main.allow-circular-references` | `true` | 允许 Bean 循环依赖,三层架构中难以完全避免 |
|
||
| `spring.main.allow-bean-definition-overriding` | `true` | 允许 Bean 覆盖,Feign 等组件可能存在重复定义 |
|
||
| `server.port` | `48081` | 服务端口号 |
|
||
|
||
### 配置导入
|
||
|
||
```yaml
|
||
spring.config.import:
|
||
- optional:classpath:application-${spring.profiles.active}.yaml
|
||
- optional:nacos:${spring.application.name}-${spring.profiles.active}.yaml
|
||
```
|
||
|
||
- **第一行**:加载本地环境配置文件(如 `application-dev.yaml`),`optional:` 表示文件不存在也不报错
|
||
- **第二行**:从 Nacos 配置中心加载 `${spring.application.name}-${spring.profiles.active}.yaml`,即 `lms-server-dev.yaml`,支持运行时动态刷新配置
|
||
|
||
---
|
||
|
||
## 二、Jackson 序列化配置
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `spring.jackson.serialization.write-dates-as-timestamps` | `true` | LocalDateTime 序列化为时间戳(毫秒数),而非字符串 |
|
||
| `spring.jackson.serialization.write-date-timestamps-as-nanoseconds` | `false` | 不使用纳秒精度,输出 `1611460870401` 而非 `1611460870.401` |
|
||
| `spring.jackson.serialization.write-durations-as-timestamps` | `true` | Duration 类型序列化为时间戳 |
|
||
| `spring.jackson.serialization.fail-on-empty-beans` | `false` | 允许序列化无属性 Bean,避免空对象报错 |
|
||
|
||
---
|
||
|
||
## 三、缓存配置
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `spring.cache.type` | `REDIS` | 缓存类型为 Redis |
|
||
| `spring.cache.redis.time-to-live` | `1h` | 缓存默认过期时间为 1 小时 |
|
||
|
||
---
|
||
|
||
## 四、日志配置
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `logging.file.name` | `${user.home}/logs/${spring.application.name}.log` | 日志文件输出到用户目录下的 `logs/lms-server.log` |
|
||
|
||
---
|
||
|
||
## 五、接口文档配置 (SpringDoc + Knife4j)
|
||
|
||
Knife4j 是 Swagger 的增强实现,用于生成和展示 API 文档。
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `springdoc.api-docs.enabled` | `true` | 启用 OpenAPI 元数据接口 `/v3/api-docs` |
|
||
| `springdoc.swagger-ui.enabled` | `true` | 启用 Swagger UI 界面 `/swagger-ui` |
|
||
| `springdoc.default-flat-param-object` | `true` | GET 请求的复杂参数展开为平铺字段 |
|
||
| `knife4j.enable` | `true` | 启用 Knife4j 增强 |
|
||
| `knife4j.setting.language` | `zh_cn` | UI 界面语言为简体中文 |
|
||
|
||
---
|
||
|
||
## 六、MyBatis-Plus 配置
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `mybatis-plus.configuration.map-underscore-to-camel-case` | `true` | 数据库下划线字段自动映射到 Java 驼峰属性(如 `create_time` → `createTime`) |
|
||
| `mybatis-plus.global-config.db-config.id-type` | `NONE` | ID 生成策略由 `IdTypeEnvironmentPostProcessor` 根据数据源类型自动适配(MySQL → AUTO,Oracle → INPUT) |
|
||
| `mybatis-plus.global-config.db-config.logic-delete-value` | `1` | 逻辑删除标记值:已删除 |
|
||
| `mybatis-plus.global-config.db-config.logic-not-delete-value` | `0` | 逻辑删除标记值:未删除 |
|
||
| `mybatis-plus.global-config.banner` | `false` | 关闭 MyBatis-Plus 启动 Banner |
|
||
| `mybatis-plus.type-aliases-package` | `${nl.info.base-package}.dal.dataobject` | 类型别名扫描包,实际为 `cn.code.nl.module.lms.dal.dataobject` |
|
||
| `mybatis-plus.encryptor.password` | `XDV71a+xqStEA3WH` | 数据库字段加解密密钥(用于加密敏感字段) |
|
||
| `mybatis-plus-join.banner` | `false` | 关闭 MyBatis-Plus-Join 启动 Banner |
|
||
|
||
---
|
||
|
||
## 七、Redis 配置
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `spring.data.redis.repositories.enabled` | `false` | 禁用 Spring Data Redis 的 Repository 功能,项目未使用该特性,禁用可加快启动速度 |
|
||
|
||
---
|
||
|
||
## 八、Easy-Trans 数据翻译配置
|
||
|
||
Easy-Trans 是一个 VO 数据翻译框架,用于自动将 ID 转换为对应的名称等(如 `deptId` → `部门名称`)。
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `easy-trans.is-enable-global` | `false` | 禁用全局翻译拦截器(对所有 SpringMVC 响应自动翻译),因为全局拦截对性能有影响。需要翻译时通过 `@Trans` 注解手动指定 |
|
||
|
||
---
|
||
|
||
## 九、RocketMQ 消息队列配置
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `rocketmq.producer.group` | `${spring.application.name}_PRODUCER` | 生产者分组名,实际为 `lms-server_PRODUCER` |
|
||
|
||
> 实际连接地址在 `application-dev.yaml` 中指定为 `127.0.0.1:9876`
|
||
|
||
---
|
||
|
||
## 十、XXL-JOB 定时任务配置
|
||
|
||
XXL-JOB 是分布式任务调度平台。
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `xxl.job.executor.appname` | `${spring.application.name}` | 执行器名称,用于调度中心识别 |
|
||
| `xxl.job.executor.logpath` | `${user.home}/logs/xxl-job/${spring.application.name}` | 任务执行日志存储路径 |
|
||
| `xxl.job.accessToken` | `123456` | 执行器与调度中心的通信 Token |
|
||
|
||
---
|
||
|
||
## 十一、芋道 (nl) 自定义配置
|
||
|
||
### 11.1 基础信息
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `nl.info.version` | `1.0.0` | 应用版本号 |
|
||
| `nl.info.base-package` | `cn.code.nl.module.lms` | **核心配置**,用于 `@MapperScan` 扫描 Mapper、MyBatis 类型别名等 |
|
||
|
||
### 11.2 Admin UI
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `nl.web.admin-ui.url` | `http://dashboard.nl.iocoder.cn` | 前端管理后台地址,用于跨域配置和 Cookie 域名设置 |
|
||
|
||
### 11.3 XSS 防护
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `nl.xss.enable` | `false` | 关闭 XSS 过滤器 |
|
||
| `nl.xss.exclude-urls` | `${management.endpoints.web.base-path}/**` | 排除 Actuator 端点,不进行 XSS 过滤 |
|
||
|
||
### 11.4 API 加解密
|
||
|
||
通过 AES 算法对请求体和响应体进行加解密,防止明文传输。
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `nl.api-encrypt.enable` | `true` | 开启 API 加解密 |
|
||
| `nl.api-encrypt.algorithm` | `AES` | 加密算法 |
|
||
| `nl.api-encrypt.request-key` | `52549111389893486934626385991395` | 请求解密密钥(AES 需要 16/24/32 位) |
|
||
| `nl.api-encrypt.response-key` | `96103715984234343991809655248883` | 响应加密密钥(AES 需要 16/24/32 位) |
|
||
|
||
> 注释中的长字符串是 RSA 模式的示例密钥,当前未使用
|
||
|
||
### 11.5 Swagger 文档信息
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `nl.swagger.title` | `管理后台` | API 文档标题 |
|
||
| `nl.swagger.description` | `提供管理员管理的所有功能` | API 文档描述 |
|
||
| `nl.swagger.version` | `${nl.info.version}` | API 文档版本号 |
|
||
|
||
### 11.6 多租户配置
|
||
|
||
多租户用于 SaaS 场景,数据按租户隔离。
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `nl.tenant.enable` | `true` | 开启多租户功能 |
|
||
| `nl.tenant.ignore-urls` | (空) | 不进行租户过滤的 URL |
|
||
| `nl.tenant.ignore-visit-urls` | `/admin-api/system/user/profile/**`, `/admin-api/system/auth/**` | 登录和个人信息接口跳过租户校验 |
|
||
| `nl.tenant.ignore-tables` | (空) | 不进行租户隔离的表 |
|
||
| `nl.tenant.ignore-caches` | `user_role_ids`, `permission_menu_ids` 等 | 不按租户隔离的缓存 Key |
|
||
|
||
### 11.7 短信验证码配置
|
||
|
||
| 配置项 | 值 | 说明 |
|
||
|--------|-----|------|
|
||
| `nl.sms-code.expire-times` | `10m` | 验证码有效期 10 分钟 |
|
||
| `nl.sms-code.send-frequency` | `1m` | 发送频率限制:每 1 分钟只能发一次 |
|
||
| `nl.sms-code.send-maximum-quantity-per-day` | `10` | 每天最多发送 10 次 |
|
||
| `nl.sms-code.begin-code` | `9999` | 测试用的固定验证码(范围起始) |
|
||
| `nl.sms-code.end-code` | `9999` | 测试用的固定验证码(范围结束),两个同时为 9999 表示固定使用 9999 作为验证码 |
|
||
|
||
---
|
||
|
||
## 十二、配置间的层级关系
|
||
|
||
```
|
||
application.yaml (主配置)
|
||
├── nl.info.base-package = cn.code.nl.module.lms ← 贯穿全局的核心配置
|
||
│ ├── @MapperScan(value = "${nl.info.base-package}") → 扫描 Mapper
|
||
│ └── type-aliases-package = ${nl.info.base-package}.dal.dataobject → DO 类型别名
|
||
│
|
||
├── application-{profile}.yaml (环境配置,如 application-dev.yaml)
|
||
│ ├── 数据库连接 (datasource)
|
||
│ ├── Redis 连接
|
||
│ ├── Nacos 地址
|
||
│ └── RocketMQ / Kafka / RabbitMQ 连接
|
||
│
|
||
└── Nacos 配置中心
|
||
└── lms-server-dev.yaml (运行时动态配置)
|
||
```
|
||
|
||
> **注意**:`application.yaml` 中的配置优先级最低,会被 profile 文件和 Nacos 远程配置覆盖。
|