You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Cloud Gateway:如何让特定路由忽略默认断路器过滤器?

解决方案

可以让已配置特定断路器的路由忽略默认断路器过滤器,具体做法是在目标路由的过滤器列表中添加RemoveDefaultFilter过滤器,排除默认的CircuitBreaker过滤器:

修改swapi-planets路由的配置如下:

routes:
  - id: swapi-planets
    uri: https://swapi.dev/api/planets/
    predicates:
      - Path=/api/planets/**
    filters:
      - name: RemoveDefaultFilter
        args:
          name: CircuitBreaker
      - name: CircuitBreaker
        args:
          fallbackUri: https://swapi.dev/api/species/
  - id: swapi-species
    uri: https://swapi.dev/api/species/
    predicates:
      - Path=/api/species/**
default-filters:
  - name: CircuitBreaker
    args:
      name: myCircuitBreaker

原理说明

  • RemoveDefaultFilter过滤器的作用是从当前路由的过滤器链中移除指定名称的默认过滤器,这里指定移除CircuitBreaker,就能让swapi-planets路由不再应用默认配置的myCircuitBreaker。
  • 之后该路由只会使用自己配置的CircuitBreaker过滤器,触发降级时会返回你指定的fallbackUri对应的内容,而非默认断路器的504响应。

另外需要注意你原配置里swapi-planets的uri存在拼写错误(多了一个s),建议修正为https://swapi.dev/api/planets/,避免不必要的请求错误。

内容的提问来源于stack exchange,提问作者renanvm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 13:15:38