codingas.com 通过 application.yml 与环境变量配置。所有可变参数均支持环境变量注入(${VAR:default} 语法)。配置文件位于 gateway-boot/src/main/resources/。
| 配置项 | 环境变量 | 默认值 | 说明 |
|---|
server.port | SERVER_PORT | 8080 | 服务端口 |
server.address | SERVER_ADDRESS | 0.0.0.0 | 绑定地址 |
spring.profiles.active | SPRING_PROFILES_ACTIVE | local | 激活的 profile |
| 配置项 | 环境变量 | 默认值 | 说明 |
|---|
spring.datasource.url | DB_URL | H2 文件 | JDBC URL |
spring.datasource.driver-class-name | DB_DRIVER | org.h2.Driver | 驱动类 |
spring.datasource.username | DB_USERNAME | sa | 数据库用户 |
spring.datasource.password | DB_PASSWORD | 空 | 数据库密码 |
spring.datasource.hikari.maximum-pool-size | HIKARI_MAX_POOL_SIZE | 10 | 连接池上限 |
spring.datasource.hikari.minimum-idle | HIKARI_MIN_IDLE | 5 | 最小空闲连接 |
PostgreSQL 模式示例:
url: jdbc:postgresql://localhost:5432/llm_gateway
driver-class-name: org.postgresql.Driver
默认关闭(local/dev profile),postgresql/prod profile 启用。
| 配置项 | 环境变量 | 默认值 | 说明 |
|---|
spring.data.redis.enabled | - | false | 是否启用 Redis |
spring.data.redis.host | REDIS_HOST | localhost | Redis 主机 |
spring.data.redis.port | REDIS_PORT | 6379 | Redis 端口 |
spring.data.redis.password | REDIS_PASSWORD | 空 | Redis 密码 |
| 配置项 | 环境变量 | 默认值 | 说明 |
|---|
gateway.security.encryption-key | ENCRYPTION_KEY | 空 | API Key 加密密钥(Base64 32 字节,生产必填) |
生成密钥:
密钥获取顺序:配置属性 → 环境变量 ENCRYPTION_KEY → 开发环境临时密钥。GATEWAY_ENCRYPTION_KEY 仅在 local profile 的 yml 映射中生效。非开发 profile 未配置时启动抛 ENCRYPTION_KEY_MISSING。密钥丢失将导致已加密的上游 Key 无法解密。
| 配置项 | 默认值 | 说明 |
|---|
gateway.security.rate-limit.bucket-size | 100 | 令牌桶容量 |
gateway.security.rate-limit.refill-rate | 10 | 每秒补充令牌数 |
gateway.security.rate-limit.qps-threshold | 1000 | QPS 阈值 |
| 配置项 | 默认值 | 说明 |
|---|
gateway.retry.max-attempts | 3 | 默认最大重试次数 |
gateway.retry.backoff-initial | 1000(ms) | 退避起始间隔 |
gateway.retry.backoff-multiplier | 2.0 | 退避倍率 |
gateway.retry.retryable-status-codes | 429,500,502,503 | 可重试状态码 |
gateway.retry.rate-limit.* | 5 次 / 2000ms 起 / 60s 封顶 | 上游限流专用策略 |
gateway.retry.fast-retry.* | 2 次 / 固定 500ms | 超时快速重试策略 |
gateway.retry.service-unavailable.* | 3 次 / 固定 5000ms | 服务不可用策略 |
| 配置项 | 默认值 | 说明 |
|---|
webclient.connect-timeout | 5000(ms) | 连接超时 |
webclient.read-timeout | 60000(ms) | 读取超时 |
| 配置项 | 默认值 | 说明 |
|---|
gateway.init.demo-data-enabled | false(local/dev 为 true) | 是否加载示例数据 |
gateway.actuator.health.public-access | true | 健康检查公网可访问 |
gateway.protocol.gemini.enabled | true | Gemini 协议插件(上游适配扩展示例) |
gateway.health.provider.stale-threshold | 300s | Provider 健康状态过期阈值 |
gateway.health.provider.failure-threshold | 3 | 连续失败熔断阈值 |
gateway.health.provider.success-threshold | 2 | 连续成功恢复阈值 |
gateway.health.provider.probe-timeout | 10s | 健康探测超时 |
spring.jpa.ddl-auto | update(postgresql profile 为 validate) | Schema 同步策略 |
| 配置项 | 默认值 | 说明 |
|---|
sa-token.token-name | Authorization | Token 头名称 |
sa-token.token-prefix | Bearer | Token 前缀 |
sa-token.timeout | 7200 | 会话超时(秒) |
sa-token.is-read-header | true | 从 Header 读取 Token |
| 端点 | 说明 |
|---|
/actuator/health | 健康检查 |
/actuator/health/liveness | 存活探针 |
/actuator/health/readiness | 就绪探针 |
/actuator/prometheus | Prometheus 指标 |
/actuator/info | 应用信息 |
| Profile | 数据库 | Redis | 用途 |
|---|
local(默认) | H2 文件 | 关闭 | 本地开发,预置示例数据 |
dev | H2 文件 | 关闭 | 开发调试 |
postgresql | PostgreSQL | 启用 | 生产推荐 |
standalone | 同上 | Caffeine | 单机 |
prod | 同上 | 启用 | 生产 |
完整占位符清单见 gateway-boot/src/main/resources/application.yml 中 ${ENV:默认值} 定义。部署细节见 安装部署。