英文:
spring-cloud-gateway path route predicate don't accept "/"
问题
我有一个自定义的网关过滤器,它使用了在application.yml中定义的路由。当我想要将路由谓词从***/test/myTest更改为/public***时,请求返回404错误,似乎"/"没有被识别,因为我尝试将/test-myTest更改为/public,它可以正常工作。
请问如何使用格式为/name/name/**的谓词?以下是我的application.yml配置:
myTest-gateway:
default-uri: https://app
apps:
/test/myTest: mymicroservice-name
spring:
cloud:
gateway:
enabled: false
x-forwarded:
proto-enabled: false
routes:
- id: appsPrefixPathPublic
uri: ${myTest-gateway.default-uri}
predicates:
- AppPath=/test/myTest
filters:
- StripPrefix=1
- PrefixPath=/public
这是我收到的错误信息:
> 无内容
>
> < 404 NOT_FOUND Not Found < Content-Type: [application/json] <
> Content-Length: [147]
>
> {"timestamp":"2020-08-26T15:44:12.023+0000","path":"/test/myTest/whatever","status":404,"error":"Not
> Found","message":null,"requestId":"e7baeeeb-6"}
>
> java.lang.AssertionError: Status expected:<200 OK> but was:<404
> NOT_FOUND>
英文:
I have a custom gateway filter that use the route written in application.yml,
When I want to change the route predicate from /test/myTest to /public the request return 404 it seemes like the "/" is not reconized because I tried to change /test-myTest to /public and it's work.
Any idea please how can I use a predicate with this format /name/name/**
this is my application.yml :
myTest-gateway:
default-uri: https://app
apps:
/test/myTest: mymicroservice-name
spring:
cloud:
gateway:
enabled: false
x-forwarded:
proto-enabled: false
routes:
- id: appsPrefixPathPublic
uri: ${myTest-gateway.default-uri}
predicates:
- AppPath=/test/myTest
filters:
- StripPrefix=1
- PrefixPath=/public
this is the error that I got it :
> No content
>
> < 404 NOT_FOUND Not Found < Content-Type: [application/json] <
> Content-Length: [147]
>
> {"timestamp":"2020-08-26T15:44:12.023+0000","path":"/test/myTest/whatever","status":404,"error":"Not
> Found","message":null,"requestId":"e7baeeeb-6"}
>
> java.lang.AssertionError: Status expected:<200 OK> but was:<404
> NOT_FOUND>
答案1
得分: 2
从文档 :
spring:
cloud:
gateway:
routes:
- id:nameRoot
uri:https://nameservice
predicates:
- Path=/name/**
filters:
- StripPrefix=2
当通过网关对/name/blue/red
发出请求时,发送到nameservice
的请求看起来像nameservice/red
。
您应将1更改为2。
英文:
From the documentation :
spring:
cloud:
gateway:
routes:
- id: nameRoot
uri: https://nameservice
predicates:
- Path=/name/**
filters:
- StripPrefix=2
When a request is made through the gateway to /name/blue/red
, the request made to nameservice
looks like nameservice/red
.
You should change 1 to 2.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论