Spring-cloud-gateway: gateway with eureka discovery only match upper case url

Created on 26 Apr 2018  路  6Comments  路  Source: spring-cloud/spring-cloud-gateway

Just test Finchley.RC1, and eureka server version is 1.4.4.RELEASE. use lower case service id will got 404, only upper case can find service.

find in DiscoveryClientRouteDefinitionLocator:

String serviceId = instance.getServiceId();

there get the upper case serviceId, and predicate will be 'Path=/SERVICE_ID/**'.

enhancement

Most helpful comment

Setting spring.cloud.gateway.discovery.locator.lowerCaseServiceId=true in gateway service will make your service id lowercase by default

All 6 comments

one solution is add a DataBindingMethodResolver to SimpleEvaluationContext, then we can set urlExpression like 'lb://'+serviceId.toLowerCase().

Can you provide your route configuration? Does it make a difference if you use Spring Cloud Eureka Server 2.0.0.RC1?

I'm facing the same issue after upgrading to Finchley.RC1.

Requests to http://localhost:4080/service/** yield 404 error, where http://localhost:4080/SERVICE/** works fine.

Here is route definition from application.yaml:

spring:
  cloud:
    gateway:
      discovery.locator.enabled: true

Checked against Spring Cloud Eureka Server 2.0.0.RC1.

@ryanjbaxter config same as @maciejlach

After 3d2364a you can now do this:

spring.cloud.gateway.discovery.locator:
  filters: 
    - name: RewritePath
      args: 
        regexp: "'/' + serviceId.toLowerCase() + '/(?<remaining>.*)'"
        replacement: "'/$\\{remaining}'"

  predicates: 
    - name: Path
      args: 
        pattern: "'/'+serviceId.toLowerCase()+'/**'"

Though that is a lot of boiler plate for an option that will be used fairly often, so more to come.

Setting spring.cloud.gateway.discovery.locator.lowerCaseServiceId=true in gateway service will make your service id lowercase by default

Was this page helpful?
0 / 5 - 0 ratings

Related issues

re6exp picture re6exp  路  37Comments

sincang picture sincang  路  41Comments

kinsey-jian picture kinsey-jian  路  24Comments

spencergibb picture spencergibb  路  36Comments

bcelenk picture bcelenk  路  31Comments