spring-cloud-gateway
spring-cloud-gateway copied to clipboard
Gateway MVC: Cannot use Path predicate with multiple paths
Using the Path predicate with multiple paths fails with:
Unable to find operation interface org.springframework.web.servlet.function.RequestPredicate for path with args {_genkey_0=/foo, _genkey_1=/bar}
My application.yml is as follows.
cloud:
gateway:
mvc:
routes:
- id: some
uri: https://some-url
predicates:
- Path=/foo,/bar
Using a single path works.
I tested with Cloud Gateway MVC 4.1.1.
I have the same problem, did you find a solution?
I have the same problem! Do you read documentation? I think it changed the way things are done. We cant define predicate with multiple paths in YML I say its because we have gateway-MVC
I have the same problem! Do you read documentation? I think it changed the way things are done. We cant define predicate with multiple paths in YML I say its because we have gateway-MVC
I would argue that's not true, because https://docs.spring.io/spring-cloud-gateway/reference/spring-cloud-gateway-server-mvc/gateway-request-predicates.html#path-request-predicate has an example with multiple paths
@fabian-dev
bad documentation. It doesn't work, it is incorrect:
spring: cloud: gateway: routes:
Correct option is :
spring: cloud: gateway: mvc: routes:
here: https://docs.spring.io/spring-cloud-gateway/reference/spring-cloud-gateway-server-mvc/filters/addrequestheader.html#:~:text=AddRequestHeader%D0%A4%D0%B8%D0%BB%D1%8C%D1%82%D1%80-,AddRequestHeader%D0%A4%D0%B8%D0%BB%D1%8C%D1%82%D1%80,-%D0%AD%D1%82%D0%BE%20AddRequestHeader%D1%84%D0%B8%D0%BB%D1%8C%D1%82%D1%80
You can create more routes with the same parameters but different path like this:
spring:
cloud:
gateway:
mvc:
routes:
- id: auth1
uri: http://localhost:8080
predicates:
- Path=/oauth2/**
filters:
- StripPrefix=1
- id: auth2
uri: http://localhost:8080
predicates:
- Path=/login
filters:
- StripPrefix=1
- id: auth3
uri: http://localhost:8080
predicates:
- Path=/logout
filters:
- StripPrefix=1
@kempf856 Thank you, I am aware of this approach, but it will look quite odd when I have many endpoints and want to categorize them by types such as GET/POST/UPDATE/DELETE to avoid letting unnecessary requests through the gateway.