我们开始查看gateway-server种的spring.factories时,除了主要的GatewayAutoConfiguration时,还有很多其他的自动配置类,这次只看 GatewayDiscoveryClientAutoConfiguration它是做什么的,我最开始是以为它是做动态路由,结果在后续查看启动日志以及其他代码后又翻回来看发现不是。
1、自动注册服务路由
通过查询官网文档,发现下面的解释
12.4. The DiscoveryClient Route Definition Locator
You can configure the gateway to create routes based on services registered with a
DiscoveryClient
compatible service registry.To enable this, set
spring.cloud.gateway.discovery.locator.enabled=true
and make sure aDiscoveryClient
implementation (such as Netflix Eureka, Consul, or Zookeeper) is on the