gateway服启动输出台显示

2026-07-09 15:05:05.556 INFO 4632 --- main com.alibaba.nacos.common.remote.client : RpcClientFactory create a new rpc client of 4ba48cfa-0980-49c4-8412-eeffb9d5c26b_config-0

2026-07-09 15:05:05.596 INFO 4632 --- main org.reflections.Reflections : Reflections took 25 ms to scan 1 urls, producing 3 keys and 6 values

2026-07-09 15:05:05.621 INFO 4632 --- main org.reflections.Reflections : Reflections took 12 ms to scan 1 urls, producing 4 keys and 9 values

2026-07-09 15:05:05.633 INFO 4632 --- main org.reflections.Reflections : Reflections took 10 ms to scan 1 urls, producing 3 keys and 10 values

2026-07-09 15:05:05.728 INFO 4632 --- main org.reflections.Reflections : Reflections took 93 ms to scan 145 urls, producing 0 keys and 0 values

2026-07-09 15:05:05.737 INFO 4632 --- main org.reflections.Reflections : Reflections took 9 ms to scan 1 urls, producing 1 keys and 5 values

2026-07-09 15:05:05.749 INFO 4632 --- main org.reflections.Reflections : Reflections took 10 ms to scan 1 urls, producing 1 keys and 7 values

2026-07-09 15:05:05.760 INFO 4632 --- main org.reflections.Reflections : Reflections took 8 ms to scan 1 urls, producing 2 keys and 8 values

2026-07-09 15:05:05.847 INFO 4632 --- main org.reflections.Reflections : Reflections took 86 ms to scan 145 urls, producing 0 keys and 0 values

2026-07-09 15:05:05.849 INFO 4632 --- main com.alibaba.nacos.common.remote.client : 4ba48cfa-0980-49c4-8412-eeffb9d5c26b_config-0 RpcClient init label, labels = {module=config, Vipserver-Tag=null, source=sdk, Amory-Tag=null, Location-Tag=null, taskId=0, AppName=unknown}

2026-07-09 15:05:05.850 INFO 4632 --- main com.alibaba.nacos.common.remote.client : 4ba48cfa-0980-49c4-8412-eeffb9d5c26b_config-0 Register server push request handler:com.alibaba.nacos.client.config.impl.ClientWorkerConfigRpcTransportClientConfigRpcTransportClientConfigRpcTransportClientLambda325/15445627782026−07−0915:05:05.850INFO4632−−−\[main\]com.alibaba.nacos.common.remote.client:\[4ba48cfa−0980−49c4−8412−eeffb9d5c26bconfig−0\]Registerserverpushrequesthandler:com.alibaba.nacos.client.config.impl.ClientWorker325/1544562778 2026-07-09 15:05:05.850 INFO 4632 --- \[ main\] com.alibaba.nacos.common.remote.client : \[4ba48cfa-0980-49c4-8412-eeffb9d5c26b_config-0\] Register server push request handler:com.alibaba.nacos.client.config.impl.ClientWorker325/15445627782026−07−0915:05:05.850INFO4632−−−\[main\]com.alibaba.nacos.common.remote.client:\[4ba48cfa−0980−49c4−8412−eeffb9d5c26bconfig−0\]Registerserverpushrequesthandler:com.alibaba.nacos.client.config.impl.ClientWorkerConfigRpcTransportClientKaTeX parse error: Can't use function '' in math mode at position 7: Lambda$̲326/1801878707 ...LambdaKaTeX parse error: Expected 'EOF', got '&' at position 193: ...dcommon.yaml &̲ group[DEFAULT_...ConnectResetRequestHandler

2026-07-09 15:05:09.161 INFO 4632 --- t.remote.worker com.alibaba.nacos.common.remote.client : 7a25d587-1d88-4071-868d-704c8c7a58f0 Notify connected event to listeners.

2026-07-09 15:05:09.161 INFO 4632 --- main com.alibaba.nacos.common.remote.client : 7a25d587-1d88-4071-868d-704c8c7a58f0 Register server push request handler:com.alibaba.nacos.common.remote.client.RpcClient$$LambdaKaTeX parse error: Expected '}', got 'EOF' at end of input: ..., replacement=/{remaining}} to RewritePath

2026-07-09 15:05:09.627 DEBUG 4632 --- oundedElastic-2 o.s.c.g.r.RouteDefinitionRouteLocator : RouteDefinition ReactiveCompositeDiscoveryClient_gateway-service applying filter {regexp=/gateway-service/?(?.*), replacement=/KaTeX parse error: Expected 'EOF', got '}' at position 12: {remaining}}̲ to RewritePath...{remaining}} to RewritePath

2026-07-09 15:05:39.271 DEBUG 4632 --- oundedElastic-3 o.s.c.g.r.RouteDefinitionRouteLocator : RouteDefinition matched: ReactiveCompositeDiscoveryClient_gateway-service

2026-07-09 15:05:39.271 DEBUG 4632 --- oundedElastic-3 o.s.c.g.r.RouteDefinitionRouteLocator : RouteDefinition app-service applying {_genkey_0=/app-service/**} to Path

2026-07-09 15:05:39.272 DEBUG 4632 --- oundedElastic-3 o.s.c.g.r.RouteDefinitionRouteLocator : RouteDefinition app-service applying filter {_genkey_0=1} to StripPrefix

2026-07-09 15:05:39.272 DEBUG 4632 --- oundedElastic-3 o.s.c.g.r.RouteDefinitionRouteLocator : RouteDefinition matched: app-service

=========================================================

这是一份 Spring Cloud Gateway 微服务网关 的启动日志,完整记录了应用从初始化到成功注册至 Nacos 并开始提供路由服务的全过程。下面按阶段拆解关键信息:

1️⃣ Nacos 客户端初始化与连接 (Config & Naming)

Config 客户端 (用于配置中心)

创建了 RPC 客户端 4ba48cfa-0980-49c4-8412-eeffb9d5c26b_config-0,并成功连接到本地的 Nacos Server (127.0.0.1:8848)。

Naming 客户端 (用于服务注册与发现)

创建了另一个 RPC 客户端 7a25d587-1d88-4071-868d-704c8c7a58f0,同样成功连接到 Nacos。

这两个客户端分别负责从 Nacos 拉取配置和进行服务注册/发现,是微服务架构的基础。

2️⃣ Reflections 扫描

org.reflections.Reflections 输出了一系列扫描日志,耗时均在毫秒级,用于扫描类路径上的注解和元数据。这是某些框架(如 Sentinel、Spring Data)内部的自检,正常情况,不影响启动。

3️⃣ Nacos 配置加载与激活 Profile

Nacos 配置中心尝试拉取多个 Data ID:common.yaml、gateway-service、gateway-service.yaml、gateway-service-dev.yaml。

其中前三个出现 WARN Ignore the empty nacos configuration,表示这些配置项在 Nacos 中不存在或内容为空,并非错误,应用会忽略并继续加载存在的配置。

最终成功加载了 gateway-service-dev.yaml、gateway-service.yaml、gateway-service、common.yaml 四个配置源。

激活的 Profile:dev(来自 spring.profiles.active),因此最终使用的是 gateway-service-dev.yaml 中的配置(优先级最高)。

4️⃣ Spring Data Redis 扫描

RepositoryConfigurationDelegate 提示进入了严格仓库模式,并扫描了 Redis 仓库,但发现 0 个 Redis Repository 接口。这说明项目引入了 spring-boot-starter-data-redis,但并未定义自定义的 Redis Repository,只是作为缓存或操作客户端使用,不影响网关功能。

5️⃣ Gateway 静态路由配置加载

从 GatewayProperties 中加载了静态路由定义(来自配置文件或代码):

text

RouteDefinition{id='app-service', predicates=Path=/app-service/\*\*, filters=StripPrefix=1, uri=lb://app-service}

这条路由的含义:

匹配路径 /app-service/** 的请求;

去掉第一段路径前缀(StripPrefix=1);

转发到注册中心中的 app-service 服务(lb:// 表示负载均衡)。

6️⃣ 加载 Gateway 内置的 PredicateFactory 和 FilterFactory

日志列出了所有可用的路由断言工厂(如 Path、Method、Header 等)以及过滤器工厂,这是 Gateway 启动时的常规初始化,表明网关已准备好解析各类路由规则。

7️⃣ Sentinel 集成(流量控制)

text

Sentinel SpringCloudGateway using AnonymousBlockRequestHandler, responseStatus: 429, responseBody: {"code":429,"message":"请求过于频繁,请稍后再试"}

Sentinel SpringCloudGateway register SentinelGatewayFilter with order: -2147483648

Sentinel SpringCloudGateway register SentinelGatewayBlockExceptionHandler

Sentinel 已自动配置,采用默认的限流响应(HTTP 429,消息为"请求过于频繁,请稍后再试"),并注册了网关过滤器和异常处理器,用于后续对路由进行流量控制。

8️⃣ 动态路由加载(服务发现)

在启动后期,RouteDefinitionRouteLocator 从 服务发现 中加载了动态路由:

text

RouteDefinition ReactiveCompositeDiscoveryClient_gateway-service applying {pattern=/gateway-service/} to Path
...
filter {regexp=/gateway-service/?(?.*), replacement=/${remaining}} to RewritePath
这意味着 Gateway 自动为注册到 Nacos 的服务 gateway-service 自身(即本应用)生成了一条动态路由,路径为 /gateway-service/
,并剥离前缀后转发到本服务的根路径。这是一种自引用路由,通常用于内部测试或调试。

同时,之前定义的静态路由 app-service 也被再次确认加载。

9️⃣ Netty Web 服务器启动与端口绑定

text

Netty started on port 8080

Gateway 基于 Spring WebFlux,底层使用 Netty 作为嵌入式 Web 服务器,成功监听 8080 端口,准备接收外部请求。

🔟 Nacos 服务注册成功

text

nacos registry, DEFAULT_GROUP gateway-service 192.168.0.28:8080 register finished

当前网关服务以 gateway-service 为服务名,IP 192.168.0.28,端口 8080,成功注册到 Nacos 的 DEFAULT_GROUP 分组中,可供其他服务发现和调用。

1️⃣1️⃣ 应用启动完成

text

Started GatewayApplication in 5.354 seconds (JVM running for 5.812)

整个启动耗时约 5.3 秒,应用已就绪。

1️⃣2️⃣ 启动后 Nacos 动态监听与路由刷新

Nacos 配置监听器启动,监听上述四个 Data ID 的变更,以实现配置热更新。

之后反复打印 DEBUG 日志,表示 RouteDefinitionRouteLocator 持续监控路由定义的变化,并重新匹配路由。这是 Gateway 的正常运行时行为,每当路由配置(从 Nacos 或服务发现)更新时,都会重新计算路由映射。

🔍 总结:当前网关提供的路由能力

静态路由:/app-service/** → 转发至 app-service(负载均衡)。

动态服务发现路由:/gateway-service/** → 转发至本服务根路径(自引用)。

限流能力:集成 Sentinel,可针对任意路由配置流量控制规则。

配置中心:已与 Nacos 连接,支持运行时动态调整路由、过滤器等配置。

应用已正常启动,准备接收外部 HTTP 请求。⚠️ 注意:由于 allowCredentials(true) 和 addAllowedOriginPattern("*") 同时存在(虽未在日志中直接体现,但之前的 CORS 配置代码已给出),在生产环境中建议收紧来源,避免安全风险。

相关推荐
豆瓣鸡1 天前
网关、服务 userId 透传
java·微服务·gateway
Sean‘8 天前
GitLab 升级后 502:Puma 反复重启问题处理记录
docker·gateway·gitlab
Hadoop_Liang1 个月前
使用Kubernetes Gateway API实现域名访问应用
容器·kubernetes·gateway
worilb1 个月前
Spring Cloud 学习与实践(9):Gateway + JWT 统一鉴权
学习·spring cloud·gateway
Dontla1 个月前
Kong Gateway(OSS)(Open Source Software)与 Kong Gateway(Enterprise)区别
gateway·kong
yxl874646461 个月前
磐创PCTG-9013 Modbus转ProfibusDP工业协议转换器
网络·科技·物联网·gateway·信息与通信
__log1 个月前
401鉴权问题完全指南:从“门卫拦人“到“畅通无阻“
gateway
暗夜猎手-大魔王1 个月前
hermes源码学习8--Gateway 内部机制
人工智能·gateway
JJJennie7771 个月前
从苹果 2026 落地场景,看系统级 Agent 时代的隐私边界与 MAI Gateway 的企业Token治理
人工智能·gateway·apple