gateway

route配置

复制代码
 @Bean
    public RouteLocator myRoute(RouteLocatorBuilder builder){
        return builder.routes()
                .route("deal-server",p->p
                                .method("GET").and()
                                .path("/deal/**")
                        .uri("http://localhost:8888")
                        )
                .route("chat-server",predicateSpec -> {
                    return predicateSpec.method("GET")
                            .and().path("/chat/**")
                            .uri("http://localhost:8848");
                })
                .build();
    }

application

复制代码
spring:
  config:
    import: nacos:gateway-server.properties
  cloud:
    nacos:
      discovery:
        server-addr: http://localhost:8848
      config:
        server-addr: http://localhost:8848
  main:
    web-application-type: reactive
  application:
    name: gateway-server

一些Ant路径模式的常见用法

单字符匹配 ?

? 代表匹配路径中的一个字符。

例如:/user? 可以匹配 /user1、/user2,但不能匹配 /users。

多字符匹配 *

  • 代表匹配路径中的任意数量的字符(包括零个字符)。
    例如:/users/* 可以匹配 /users/123、/users/profile,但不能匹配 /users。

多级路径匹配 **

** 代表匹配路径中的任意数量的路径段,包括零个路径段。

例如:/users/** 可以匹配 /users/、/users/123、/users/123/profile。

路径分隔符 /

/ 用于分隔路径中的各个部分。

例如:/users/profile 匹配路径 /users/profile。

相关推荐
Maiko Star2 小时前
Gateway网关拦截自定义header & 用户上下文打通实战
gateway·threadlocal
skywalk81633 天前
LLM API Gateway:使用Comate Spec Mode创建大模型调用中转服务器
服务器·人工智能·gateway·comate
我是小妖怪,潇洒又自在3 天前
springcloud alibaba(七)Gateway--服务网关
spring·spring cloud·gateway
boy快快长大6 天前
【Spring Cloud Alibaba】Gateway(一)
数据库·gateway
谷隐凡二7 天前
网关的核心概念及简单演进介绍
gateway
摇滚侠7 天前
2025最新 SpringCloud 教程,Gateway-过滤器-基本使用,笔记58
笔记·spring cloud·gateway
摇滚侠7 天前
2025最新 SpringCloud 教程,Gateway-过滤器-globalFilter,笔记60
笔记·spring cloud·gateway
摇滚侠7 天前
2025最新 SpringCloud 教程,Gateway-过滤器-默认过滤器,笔记59
笔记·spring cloud·gateway
摇滚侠7 天前
2025最新 SpringCloud 教程,Gateway-过滤器-自定义,全局跨域,总结,笔记61,笔记62,笔记63
笔记·spring cloud·gateway