3
votes

I want enable default routing in my spring cloud gateway (no zuul) by service ids registered in eureka (application names) but I always got 404 error.

In my chat service's bootstrap.yml I have defined application name

spring:
  application:
    name: chat-service

and in application properties:

eureka:
  instance:
    preferIpAddress: true
  client:
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://${EUREKA_HOST:localhost}:${EUREKA_PORT:8761}/eureka/

when I go to eureka's dashboard I can see registered my chat service and gateway as well.

Eureka's configuration in gateway application is same as chat service, but I also have this:

spring:
  application:
    name: gateway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true

and next I also tried add explicit routes which din't work as well, but if I have discovery locator enabled set to true this shouldn't be needed right?

  routes:
    - id: chat-service-route
      uri: lb://chat-service
      predicates:
        - Path=** 

I created test endpoint which I tried call directly on chat service and also with gateway. Direct call works fine so issue will be with routing.

@RestController
@RequestMapping
public class TestController {

    @GetMapping
    public String test() {
        return "chat-service ready";
    }
}

What I did wrong? I am little desperate. I am using spring boot 2.2.2 and Hoxton.RELEASE cloud dependencies version

1
Can you explain what "doesn't work" means? What url did you try? - spencergibb
@spencergibb I'm sorry I should wrote it more cleaner. I always got 404 error for rest endpoint in chat service when I call it from gateway - Denis Stephanov
What url are you calling on the gateway? - spencergibb
@spencergibb gateway runs on 8080 so I call localhost:8080/chat-service - Denis Stephanov
And does chat service respond to /chat-service? Otherwise you need to rewrite the path - spencergibb

1 Answers

2
votes

Try removing explicit routes and add below property to application yml. This works for me.

spring:
  cloud:
    gateway:
      discovery:
        locator:
          lower-case-service-id: true