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

场景:

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

配置如下:

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

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

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

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 文件

 

最后:

修改后,正常使用了!

posted @ 2019-11-12 14:08  andrew-chen  阅读(591)  评论(0编辑  收藏  举报