【发布时间】:2020-03-26 08:51:15
【问题描述】:
我目前正在实施 Spring Cloud 希望将我的路由指定到多个文件中,例如:
最初,我们有一个配置有到 A 和 B 休息端点的路由。
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 Endpoint C 的路由。我不想触及原始配置(YML 1),而是想为 C 创建一个新的 YML 并期望路由 C 附加到 A 和 B 的原始路由(类似于 Apache Httpd WebProxy)。
要拥有多个 YML,我参考以下链接中的建议: Spring Boot and multiple external configuration files
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)
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
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
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
如果其他人对如何实现这一点有任何好的想法,请提出建议。 非常欢迎所有帮助和 cmets。
【问题讨论】: