1

I was trying microservice with eureka discovery server, api gateway and one rest service. Like shown in below image

  • [Eureka discovery][1]

For Service discovery:

  • I have added relevant pom dependencies
  • I have added annotations to make spring boot project as discovery service

application.yml:-

server:
  port: 8761
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false

For Spring boot service 1:-

  • Added @EnableEurekaClient at main class

application.yml

server:
  port: 9009
spring:
  application:
    name: HEALTH-CARD
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://${eureka.instance.hostname}:8761/eureka/

For Api-Gateway service:-

  • Added @EnableEurekaClient at main class

application.yml

server:
  port: 8080
spring:
  application:
    name: API-GATEWAY
    cloud:
      gateway:
        discovery:
          locator:
            enabled: true
        routes:
          - id: health-card
            uri: http://localhost:9009/health-card
            predicates:
              - Path=/**
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://${eureka.instance.hostname}:8761/eureka/
  • Also I have tried with java class route config part
package com.apigateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringApiGatewayConfig {
    public RouteLocator configRoute(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("healthCard", r->r.path("/health-card/**").uri("localhost:9009/")).build();
    }
}

Even I have tried all the suggestion from below link Spring Cloud API Gateway routing not working But nothing worked for me. Please help me on this wired case. [1]: https://i.stack.imgur.com/pGwlB.jpg

Prakash
  • 19
  • 2

1 Answers1

0

You may want to try and outdent the spring cloud line in your application yaml

server:
  port: 8080
spring:
  application:
    name: API-GATEWAY
  cloud:
    gateway:
      ...

spring.cloud is a peer of spring.application and your example has it as a child.

incomplete-co.de
  • 2,137
  • 18
  • 23