Spring Cloud Gateway Server MVC
章节总结
📄️ 如何集成 Spring Cloud Gateway 服务器 MVC
要在项目中包含 Spring Cloud Gateway Server MVC,请使用组 ID 为 org.springframework.cloud 且工件 ID 为 spring-cloud-starter-gateway-mvc 的 starter。有关使用当前 Spring Cloud Release Train 设置构建系统的详细信息,请参阅 Spring Cloud 项目页面。
📄️ 术语表
路由(Route):网关的基本构建块。它由一个 ID、一个目标 URI、一组断言(predicates)和一组过滤器(filters)定义。如果聚合断言为真,则路由匹配成功。
📄️ 工作原理
以下图表提供了 Spring Cloud Gateway 工作原理的高级概述:
📄️ Java 路由 API
Spring Cloud Gateway Server MVC 使用 Spring WebMvc.fn 的 RouterFunctions.Builder 作为创建路由的默认方式,这些路由是 WebMvc.fn 的 RouterFunction 实例。
📄️ 网关请求谓词
Spring Cloud Gateway MVC 将路由匹配作为 Spring WebMvc.fn 的 HandlerMapping 基础设施的一部分。Spring Cloud Gateway 重用了许多来自 WebMvc.fn 的 RequestPredicate 实现,并包含其他自定义的 RequestPredicate 实现。所有这些断言都匹配 HTTP 请求的不同属性。你可以使用 RequestPredicate.and() 和 RequestPredicate.or() 方法将多个路由断言工厂组合在一起。
🗃️ Gateway Handler Filter Functions
31 个项目
📄️ 编写自定义谓词和过滤器
Spring Cloud Gateway Server MVC 使用 Spring WebMvc.fn API(javadoc)作为 API 网关功能的基础。
📄️ 使用 Servlet 和 Servlet 过滤器
Spring Cloud Gateway Server MVC 是为构建在 Servlet API 上并部署到 Servlet 容器的 Servlet 栈 Web 应用程序而设计的。如果你的应用程序使用了 Servlets 或 Servlet Filters,你可能需要注意它们的顺序。