{“msg“:“invalid token“,“code“:401} 问题解决

本文详细介绍了Spring Cloud Gateway的路由配置,包括如何设置精确和模糊路由,以及过滤器的使用,如RewritePath,用于实现API路径的重写和服务间的端口替换。通过配置,确保了访问权限的检查和路由顺序的正确性,从而优化了微服务间的通信效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述
非法令牌、如果没有登录、没有访问权限、访问就出现
检查是否登录
检查路由的顺序
精确路由高优先级 放在前、
模糊路由低优先级 放在后

spring:
  cloud:
    gateway:
      routes:
        - id : product_route
          uri: lb://gulimall-fast
          predicates:
            - Path=/api/product/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{segment}
## https://localhost:88/api/product/list/tree ---> https://localhost:10000//product/list/tree  找到gulimall-fast服务换端口10000,正则去掉api
        - id : admin_route
          uri: lb://renren-fast
          predicates:
            - Path=/api/**
          filters :
            - RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment}
## https://localhost:88/api/a.jpg ---> https://localhost:8080/renren-fast/a.jpg   找renren-fast服务换端口8080、正则 把api换成renren-fast

模糊断言要写在精确断言后

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值