跳到主要内容
版本:5.0.1

FallbackHeaders GatewayFilter 工厂

DeepSeek V3 中英对照 FallbackHeaders GatewayFilter Factory FallbackHeaders GatewayFilter Factory

FallbackHeaders 工厂允许您在转发到外部应用程序中 fallbackUri 的请求头中添加 Spring Cloud CircuitBreaker 执行异常详情,如下所示场景:

spring:
cloud:
gateway:
routes:
- id: ingredients
uri: lb://ingredients
predicates:
- Path=//ingredients/**
filters:
- name: CircuitBreaker
args:
name: fetchIngredients
fallbackUri: forward:/fallback
- id: ingredients-fallback
uri: http://localhost:9994
predicates:
- Path=/fallback
filters:
- name: FallbackHeaders
args:
executionExceptionTypeHeaderName: Test-Header

在这个例子中,当断路器运行时发生执行异常后,请求会被转发到运行在 localhost:9994 上的应用程序中的 fallback 端点或处理器。FallbackHeaders 过滤器会向该请求添加包含异常类型、异常消息以及(如果可用)根本原因异常类型和消息的头部信息。

您可以通过设置以下参数的值来覆盖配置中的标题名称(显示为默认值):

  • executionExceptionTypeHeaderName ("Execution-Exception-Type")

  • executionExceptionMessageHeaderName ("Execution-Exception-Message")

  • rootCauseExceptionTypeHeaderName ("Root-Cause-Exception-Type")

  • rootCauseExceptionMessageHeaderName ("Root-Cause-Exception-Message")

有关断路器和网关的更多信息,请参阅 Spring Cloud CircuitBreaker Factory 部分。