[JAVA] SpringCloudGateway动态路由Apollo实现详解

1809 0
王子 2022-11-8 17:22:12 | 显示全部楼层 |阅读模式
目录

    背景路由的加载实现动态路由


背景

在之前我们了解的Spring Cloud Gateway配置路由方式有两种方式
    通过配置文件
  1. spring:
  2.   cloud:
  3.     gateway:
  4.       routes:
  5.         - id: test
  6.           predicates:
  7.             - Path=/ms/test/*
  8.           filters:
  9.             - StripPrefix=2
  10.           uri: http://localhost:9000
复制代码
    通过JavaBean
  1.     @Bean
  2.     public RouteLocator routeLocator(RouteLocatorBuilder builder) {
  3.         return builder.routes()
  4.                 .route(r -> r.path("/ms/test/**")
  5.                 .filters(f -> f.stripPrefix(2))
  6.                 .uri("http://localhost:9000"))
  7.                 .build();
  8.     }
复制代码
但是遗憾的是这两种方式都不支持动态路由,都需要重启服务。 所以我们需要对Spring Cloud Gateway进行改造,在改造的时候我们就需要看看源码了解下Spring Cloud Gateway的路由加载
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行