首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在中将路由分发到多个YML文件?

如何在中将路由分发到多个YML文件?
EN

Stack Overflow用户
提问于 2020-03-26 08:51:15
回答 1查看 1.3K关注 0票数 2

我目前正在实现Spring,希望将我的路由指定为多个文件,如下所示:

最初,我们有一个配置,它有通往A&B rest端点的路由。

代码语言:javascript
复制
Spring Cloud Gateway fronts Rest Endpoint A and Rest Endpoint B 
    - Created YML 1 with routes to A and B (Refer below)

YML 1
----------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteA
          uri: https://httpbin.org/
          predicates:
            - Path=/status/200
        - id: RouteB
          uri: https://httpbin.org/
          predicates:
            - Path=/status/400

几天后,我需要将路由添加到另一个Rest端点C。我不想接触原始配置(YML 1),而是希望为C创建一个新的YML,并期望路由C附加到原始路由A和B(类似于Apache )。

要有多个YML,请参考以下链接中的建议:Spring启动和多个外部配置文件

代码语言:javascript
复制
Spring Cloud Gateway fronts Rest Endpoint A, B and C
    - Existing YML 1 with routes to A and B (Refer below)
    - Created YML 2 with route to C (Refer below)
代码语言:javascript
复制
YML 1
----------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteA
          uri: https://httpbin.org/
          predicates:
            - Path=/status/200
        - id: RouteB
          uri: https://httpbin.org/
          predicates:
            - Path=/status/400

YML 2
-----------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteC
          uri: https://httpbin.org/
          predicates:
            - Path=/status/500
代码语言:javascript
复制
Expectation 
-----------------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteA
          uri: https://httpbin.org/
          predicates:
            - Path=/status/200
        - id: RouteB
          uri: https://httpbin.org/
          predicates:
            - Path=/status/400
        - id: RouteC
          uri: https://httpbin.org/
          predicates:
            - Path=/status/500
代码语言:javascript
复制
Actual Outcome 
-------------------------           
spring:
  cloud:
    gateway:
      routes:
        - id: RouteC
          uri: https://httpbin.org/
          predicates:
            - Path=/status/500

Routes(A, B, C) do not get appended, instead it only picks up the latest configuration (YML 2 - Route C) in the property chain                      

如果其他人对如何实现这一点有什么好主意,请提出建议。欢迎所有的帮助和评论。

EN

回答 1

Stack Overflow用户

发布于 2020-07-30 21:33:33

我想出的最好的方法(实际上不是什么解决方案,而是一个折衷方案)是使用大型的ASCII头(带有一些像patorjk这样的在线工具)。它使导航更容易一目了然,特别是在使用崇高文本时。

这离理想还很远,但我觉得现在还可以。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60863665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档