覆盤:錯誤理解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 文件

 

最後:

修改後,正常使用了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章