跳到主要内容

【10】 配置Gateway详解

文章目录

    • 前言
  • application.yml 配置项
  • 其他配置
    • Http超时配置
    • 使用 Java API配置路由
    • Discovery Client路由 配置谓词和过滤器
    • CORS 配置

前言

在之前介绍了一些Spring Cloud Gateway配置项,接下来详细介绍下所有配置项。

官方文档地址

application.yml 配置项

可以在application.properties、application.yml、代码、命令行开关中指定各种属性。

本附录提供了常见 Spring Cloud Gateway 属性的列表以及对使用它们的底层类的引用。

名称默认说明
spring.cloud.gateway.default-filters作用于每个路由的过滤器列表
spring.cloud.gateway.discovery.locator.enabledfalse启用服务发现,动态路由
spring.cloud.gateway.discovery.locator.filters
spring.cloud.gateway.discovery.locator.include-expressiontrue是否在网关集成中包含服务的 SpEL 表达式,默认为:true。
spring.cloud.gateway.discovery.locator.lower-case-service-idfalse在谓词和过滤器中小写 serviceId ,默认为 false。当 eureka 自动大写 serviceId 时很有用。所以 MYSERIVCE,会匹配 /myservice/**

| spring.cloud.gateway.discovery.locator.predicates | | | | spring.cloud.gateway.discovery.locator.route-id-prefix | | routeId 的前缀,默认为 discoveryClient.getClass().getSimpleName() + “_”+服务 ID 。将以创建 routeId。 |