栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringCloudGateway路由到带有context-path的微服务总是404的问题

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringCloudGateway路由到带有context-path的微服务总是404的问题

问题描述

使用SpringCloudGateway路由到带有content-path的微服务时总是404。此时的gateway的配置文件以及微服务的配置文件如下:
(此处省略其它配置)
gateway

	...
      routes:
        - id: acl_service_other
          uri: lb://acl-other-server
          predicates:
            - Path=/other/{segment}
   	...
server:
  port: 8000

service1

...
server:
  port: 9001
  servlet:
    context-path: /other
...

此时通过请求http://localhost:8000/other/test2/test2,总是报404
(经过测试,如果微服务中没有context-path,修改Path =/test2/{segment} http://localhost:8000/test2/test2是可以正常路由的)

问题处理
  1. 修改gateway的配置文件如下
      routes:
        - id: acl_service_other
          uri: lb://acl-other-server
          predicates:
            - Path=/other/**
          filters:
            ##由于微服务acl-other-server中设置了server.servlet.context-path=/other,要重写路径才能正常路由到该微服务
            - RewritePath=/other/?(?.*), /other/${segment}
  1. 重启gateway,http://localhost:8000/other/test2/test2请求成功!!

至于原因,烦请了解的大神留言~

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/602725.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号