Denis Stephanov
Denis Stephanov

Reputation: 5231

Spring cloud gateway default routing doesn't work

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

Upvotes: 3

Views: 3999

Answers (2)

Kanika Sud
Kanika Sud

Reputation: 1

In the end service:

server.port=8993
spring.application.name=department-service
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
management.endpoints.web.exposure.include=*
eureka.instance.hostname=localhost

In the api-gateway project:

server.port=9191
spring.application.name=api-gateway
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

management.endpoints.web.exposure.include=*

logging.level.root=INFO
logging.level.org.springframework.cloud.gateway=TRACE
logging.level.org.springframework.cloud.gateway.route=INFO

spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.discovery.locator.lower-case-service-id=true

Upvotes: 0

venkat
venkat

Reputation: 117

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

Upvotes: 3

Related Questions