SpringCloud 服务网关路由规则的坑

版权声明:本文为博主原创文章,转载请注明出处 浅然的专栏 https://blog.csdn.net/w_linux/article/details/83046181

一、场景简述

笔者最近用到SpringCloud 服务网关的时候,进行服务网关的路由测试,发现无法路由自己设置的规则,测试的时候如下

通过错误排查发现,原来是路由规则写错了!

路由规则如下(错误)

#端口
server:
  port: 8080
spring:
  #该配置文件中的配置,对应的服务名称是wc-gateway
  application:
    name: wc-gateway
  profiles:
    active: dev
#服务网关配置
zuul:
  host:
    connect-timeout-millis: 60000
    socket-timeout-millis: 60000
    #路由规则
    routes:
      api:
        path: /api/user/**
        serviceId: wc-client-user

二、解决方案

只需要将routes及以下的属性左移,与host相等级别即可

修改后的路由规则

#端口
server:
  port: 8080
spring:
  #该配置文件中的配置,对应的服务名称是wc-gateway
  application:
    name: wc-gateway
  profiles:
    active: dev
#服务网关配置
zuul:
  host:
    connect-timeout-millis: 60000
    socket-timeout-millis: 60000
  #路由规则
  routes:
    api:
      path: /api/user/**
      serviceId: wc-client-user

好了,问题解决,我们重启应用测试,测试结果和预期一样。

猜你喜欢

转载自blog.csdn.net/w_linux/article/details/83046181