zhangjf e52e2ba801 refactor: 简化租户元数据,移除冗余的 tenant-id
问题:metadata 中同时配置 tenant-id 和 tenant-group,但 tenant-id 未被使用

分析:
- tenant-id: 用于数据隔离,但实际由 TenantContextHolder 提供,元数据中的值无意义
- tenant-group: 用于服务路由,负载均衡器实际只使用此字段

解决方案:
1. 移除 metadata.tenant-id 配置
2. 只保留 metadata.tenant-group
3. 更新 NacosMetadataConfig,移除 tenant-id 处理
4. 更新 docker-compose.yml,移除 TENANT_ID 环境变量

配置简化:
  修改前: tenant-id + tenant-group 两个字段
  修改后: 只有 tenant-group 一个字段

实例类型:
  共享实例: tenant-group = "" (空)
  VIP实例:  tenant-group = "TENANT_VIP_001"
2026-02-19 21:26:06 +08:00

94 lines
2.6 KiB
YAML

server:
port: 8100
spring:
application:
name: fund-sys
cloud:
nacos:
discovery:
server-addr: localhost:8848
namespace: fund-platform
group: DEFAULT_GROUP
username: nacos
password: nacos
# 租户路由元数据
# tenant-group: 空值=共享实例,有值=VIP专属实例
metadata:
tenant-group: ${TENANT_GROUP:}
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/fund_sys?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
username: root
password: zjf@123456
hikari:
# 连接池大小配置
maximum-pool-size: 20 # 最大连接数(建议: CPU核心数*2 + 有效磁盘数)
minimum-idle: 5 # 最小空闲连接数
# 连接超时配置
connection-timeout: 30000 # 连接超时时间(毫秒)
idle-timeout: 600000 # 空闲连接超时时间(10分钟)
max-lifetime: 1800000 # 连接最大存活时间(30分钟)
# 连接验证配置
validation-timeout: 5000 # 连接验证超时时间
leak-detection-threshold: 60000 # 连接泄露检测阈值(60秒)
# 连接池名称
pool-name: FundSysHikariPool
# 连接初始化SQL
connection-init-sql: SELECT 1
# Redis配置
data:
redis:
host: localhost
port: 6379
password: zjf@123456
database: 0
timeout: 10000
lettuce:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
type-aliases-package: com.fundplatform.sys.data.entity
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
logic-delete-field: deleted
logic-delete-value: 1
logic-not-delete-value: 0
# 租户插件配置(一库多租户模式启用)
tenant:
enabled: false # 启用后自动为 SQL 添加 tenant_id 条件
logging:
level:
com.fundplatform.sys: DEBUG
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
# 多租户路由配置(服务实例只需声明自己的租户组)
tenant:
routing:
enabled: true
tenant-header: X-Tenant-Id
tenant-group-header: X-Tenant-Group
default-tenant-id: "1"
# 共享服务列表
shared-services:
- fund-gateway
- fund-report
- fund-file
# 回退到共享实例
fallback-to-shared: true