我正在使用 springboot 網關在我的微服務之間進行負載平衡請求
spring:
application:
name: gateway-service
cloud:
gateway:
routes:
- id: baeldung
uri: question.com/questions/444/ask
- id: myOtherRouting
uri: answer.com/answers/333/answer
我的問題是,如果我發送了一個錯誤的請求,"question.com/questions/dasldkjasdas"
那么該請求將被轉發到,answer.com/answers/333/answer
因為這是我配置中的最后一個鏈,我該如何防止這種情況,并發送 notfound 狀態碼作為回應。我用了
filters:
- SetStatus=NOT_FOUND
https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.0.RELEASE/reference/html/#setstatus-gatewayfilter-factory
但這不是我認為最好的方法。
uj5u.com熱心網友回復:
您沒有predicate為您的route定義指定任何內容- 這意味著它們都匹配任何傳入請求。從Spring Cloud Gateway:
客戶端向 Spring Cloud Gateway 發出請求。如果網關處理程式映射確定請求與路由匹配,則將其發送到網關 Web 處理程式。
和
路由:路由網關的基本構建塊。它由 ID、目標 URI、謂詞集合和過濾器集合定義。如果聚合謂詞為真,則匹配路由。
由于您沒有任何predicate指定 - 您的路線與傳入請求匹配,最后一個獲勝。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/369937.html
上一篇:無法從SpringBootMongoDB中的陣列中洗掉嵌入物件
下一篇:API設計:回應資料跟蹤分析
