spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Gateway MVC: Cannot use Path predicate with multiple paths

Open fabian-dev opened this issue 1 year ago • 4 comments

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.

fabian-dev avatar Feb 06 '24 12:02 fabian-dev

I have the same problem, did you find a solution?

NiiazKhan avatar Feb 08 '24 08:02 NiiazKhan

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

NAHUEALB avatar Feb 11 '24 17:02 NAHUEALB

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 avatar Feb 14 '24 18:02 fabian-dev

@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

NiiazKhan avatar Feb 14 '24 19:02 NiiazKhan

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 avatar Feb 26 '24 08:02 kempf856

@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.

NiiazKhan avatar Feb 27 '24 08:02 NiiazKhan