• 复盘:错误理解zuul路径匹配,无法使用zuul


    场景:

    项目中用到zuul时,配置url总是有问题,无法路由到对应微服务。

    配置如下:

    zuul:
      routes:
        m2-member:
          path: /member/*
          serviceId: m2-member
        m3-order:
          path: /order/*
          serviceId: m3-order

    乍一看没什么问题,百度后也没头绪。这个时候,一般我会翻墙找找官方文档。

    在文档里我看到了这么一条:

    The preceding example means that HTTP calls to /myusers get forwarded to the users_service service.

    The route must have a path that can be specified as an ant-style pattern, so /myusers/* only matches one level, but /myusers/** matches hierarchically.

    原来/* 和 /** 是不同的!

    我又查询了ant-style pattern,记录如下:

    ? 匹配任何单字符  
    * 匹配0或者任意数量的字符  
    ** 匹配0或者更多的目录 

    举几个例子:


    /app/*.x 匹配(Matches)所有在app路径下的.x文件  
    /app/p?ttern 匹配(Matches) /app/pattern 和 /app/pXttern,但是不包括/app/pttern  
    /**/example 匹配(Matches) /app/example, /app/foo/example, 和 /example  
    /app/**/dir/file. 匹配(Matches) /app/dir/file.jsp, /app/foo/dir/file.html,/app/foo/bar/dir/file.pdf, 和 /app/dir/file.java  
    /**/*.jsp 匹配(Matches)任何的.jsp 文件

    最后:

    修改后,正常使用了!

  • 相关阅读:
    初涉数组
    声明
    简述java程序中的main方法
    概述java语言
    1.3 linux基础(三)
    linux基础之-screen命令
    1.2 linux基础(二)
    1.1 Linux基础(一)
    实验7-1-13 装箱问题
    实验7-1-12 组个最小数
  • 原文地址:https://www.cnblogs.com/andrew-chen/p/11841471.html
Copyright © 2020-2023  润新知