From e6f3f85581d7d519607f388ed38e467befdbd5a4 Mon Sep 17 00:00:00 2001 From: zhangjf Date: Sun, 22 Feb 2026 22:48:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BD=91=E5=85=B3?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?PrefixPath=E8=A1=A5=E5=85=A8API=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - StripPrefix=2 后路径缺少 /api/v1 前缀 - 健康检查路径不正确,无法访问 修改: 1. application.yml: 所有路由添加 PrefixPath=/api/v1 2. TenantGatewayFilter: 更新白名单健康检查路径 3. TokenAuthFilter: 更新白名单健康检查路径 路由流程示例: - 登录: /fund/sys/auth/login → StripPrefix=2 → /auth/login → PrefixPath=/api/v1 → /api/v1/auth/login ✓ - 健康检查: /fund/sys/sys/health → StripPrefix=2 → /sys/health → PrefixPath=/api/v1 → /api/v1/sys/health ✓ 注意:健康检查路径需要重复模块名 - /fund/{module}/{module}/health --- .../gateway/filter/TenantGatewayFilter.java | 23 ++++++++++--------- .../gateway/filter/TokenAuthFilter.java | 17 +++++++------- .../src/main/resources/application.yml | 8 +++++++ 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/fund-gateway/src/main/java/com/fundplatform/gateway/filter/TenantGatewayFilter.java b/fund-gateway/src/main/java/com/fundplatform/gateway/filter/TenantGatewayFilter.java index c61181c..00ac7f3 100644 --- a/fund-gateway/src/main/java/com/fundplatform/gateway/filter/TenantGatewayFilter.java +++ b/fund-gateway/src/main/java/com/fundplatform/gateway/filter/TenantGatewayFilter.java @@ -39,18 +39,19 @@ public class TenantGatewayFilter implements GlobalFilter, Ordered { // 白名单路径(不需要X-Tenant-Id) // 注意:路径是网关接收的原始请求路径(含/fund前缀) + // 健康检查路径需要包含模块名两次(一次用于路由,一次用于服务路径) private static final List TENANT_ID_WHITE_LIST = Arrays.asList( - "/fund/sys/auth/login", // 登录接口 - "/fund/sys/auth/logout", // 登出接口 - "/actuator/health", // 网关健康检查(无/fund前缀) - "/fund/sys/health", // 系统服务健康检查 - "/fund/cust/health", // 客户服务健康检查 - "/fund/proj/health", // 项目服务健康检查 - "/fund/exp/health", // 支出服务健康检查 - "/fund/receipt/health", // 收款服务健康检查 - "/fund/report/health", // 报表服务健康检查 - "/fund/req/health", // 请求服务健康检查 - "/fund/file/health" // 文件服务健康检查 + "/fund/sys/auth/login", // 登录接口 + "/fund/sys/auth/logout", // 登出接口 + "/actuator/health", // 网关健康检查(无/fund前缀) + "/fund/sys/sys/health", // 系统服务健康检查 (/api/v1/sys/health) + "/fund/cust/cust/health", // 客户服务健康检查 (/api/v1/cust/health) + "/fund/proj/proj/health", // 项目服务健康检查 (/api/v1/proj/health) + "/fund/exp/exp/health", // 支出服务健康检查 (/api/v1/exp/health) + "/fund/receipt/receipt/health", // 收款服务健康检查 (/api/v1/receipt/health) + "/fund/report/report/health", // 报表服务健康检查 (/api/v1/report/health) + "/fund/req/req/health", // 请求服务健康检查 (/api/v1/req/health) + "/fund/file/file/health" // 文件服务健康检查 (/api/v1/file/health) ); private final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/fund-gateway/src/main/java/com/fundplatform/gateway/filter/TokenAuthFilter.java b/fund-gateway/src/main/java/com/fundplatform/gateway/filter/TokenAuthFilter.java index 79a192f..541e208 100644 --- a/fund-gateway/src/main/java/com/fundplatform/gateway/filter/TokenAuthFilter.java +++ b/fund-gateway/src/main/java/com/fundplatform/gateway/filter/TokenAuthFilter.java @@ -40,16 +40,17 @@ public class TokenAuthFilter implements GlobalFilter, Ordered { // 白名单路径(不需要token验证) // 注意:路径是网关接收的原始请求路径(含/fund前缀) + // 健康检查路径需要包含模块名两次(一次用于路由,一次用于服务路径) private static final List WHITE_LIST = Arrays.asList( "/fund/sys/auth/login", - "/fund/sys/health", - "/fund/cust/health", - "/fund/proj/health", - "/fund/exp/health", - "/fund/receipt/health", - "/fund/report/health", - "/fund/req/health", - "/fund/file/health" + "/fund/sys/sys/health", + "/fund/cust/cust/health", + "/fund/proj/proj/health", + "/fund/exp/exp/health", + "/fund/receipt/receipt/health", + "/fund/report/report/health", + "/fund/req/req/health", + "/fund/file/file/health" ); private final ReactiveTokenService reactiveTokenService; diff --git a/fund-gateway/src/main/resources/application.yml b/fund-gateway/src/main/resources/application.yml index ba3a9eb..c2af680 100644 --- a/fund-gateway/src/main/resources/application.yml +++ b/fund-gateway/src/main/resources/application.yml @@ -66,6 +66,7 @@ spring: - Path=/fund/sys/** filters: - StripPrefix=2 + - PrefixPath=/api/v1 # 客户管理服务 - id: fund-cust @@ -74,6 +75,7 @@ spring: - Path=/fund/cust/** filters: - StripPrefix=2 + - PrefixPath=/api/v1 # 项目管理服务 - id: fund-proj @@ -82,6 +84,7 @@ spring: - Path=/fund/proj/** filters: - StripPrefix=2 + - PrefixPath=/api/v1 # 用款申请服务 - id: fund-req @@ -90,6 +93,7 @@ spring: - Path=/fund/req/** filters: - StripPrefix=2 + - PrefixPath=/api/v1 # 支出管理服务 - id: fund-exp @@ -98,6 +102,7 @@ spring: - Path=/fund/exp/** filters: - StripPrefix=2 + - PrefixPath=/api/v1 # 收款管理服务 - id: fund-receipt @@ -106,6 +111,7 @@ spring: - Path=/fund/receipt/** filters: - StripPrefix=2 + - PrefixPath=/api/v1 # 报表服务 - id: fund-report @@ -114,6 +120,7 @@ spring: - Path=/fund/report/** filters: - StripPrefix=2 + - PrefixPath=/api/v1 # 文件服务 - id: fund-file @@ -122,6 +129,7 @@ spring: - Path=/fund/file/** filters: - StripPrefix=2 + - PrefixPath=/api/v1 # 多租户路由配置 tenant: