Configuring Route Predicate Factories and Gateway Filter Factories

有两种方法来配置谓词和过滤器:快捷方式和完全展开的参数。以下大多数示例使用快捷方式。

There are two ways to configure predicates and filters: shortcuts and fully expanded arguments. Most examples below use the shortcut way.

名称和参数名称在每个部分的第一句话或第二句话中列为 code。这些参数通常按照快捷配置所需的顺序列出。

The name and argument names are listed as code in the first sentence or two of each section. The arguments are typically listed in the order that are needed for the shortcut configuration.

Shortcut Configuration

快捷方式配置通过过滤器名称、紧随其后的等号 (=)、以及用逗号 (,) 分隔的参数值进行识别。

Shortcut configuration is recognized by the filter name, followed by an equals sign (=), followed by argument values separated by commas (,).

application.yml
spring:
  cloud:
    gateway:
      routes:
      - id: after_route
        uri: https://example.org
        predicates:
        - Cookie=mycookie,mycookievalue

前面的示例使用两个参数定义 Cookie 路由谓词工厂,即 Cookie 名称 mycookie 和要匹配的值 mycookievalue

The previous sample defines the Cookie Route Predicate Factory with two arguments, the cookie name, mycookie and the value to match mycookievalue.

Fully Expanded Arguments

完全展开的参数更类似于具有名称/值对的标准 yaml 配置。通常,存在一个 name 键和一个 args 键。args 键是用于配置谓词或过滤器的键值对图。

Fully expanded arguments appear more like standard yaml configuration with name/value pairs. Typically, there will be a name key and an args key. The args key is a map of key value pairs to configure the predicate or filter.

application.yml
spring:
  cloud:
    gateway:
      routes:
      - id: after_route
        uri: https://example.org
        predicates:
        - name: Cookie
          args:
            name: mycookie
            regexp: mycookievalue

这是上面显示的 `Cookie`谓词的快捷方式配置的完整配置。

This is the full configuration of the shortcut configuration of the Cookie predicate shown above.