FIXED Spring Cloud Gateway | No servers available for service: ms-authentication-server

168 Views Asked by At

I'm facing this issue, I'm running a few microservices in my local machine but when I try to use gateway server I got this:

No servers available for service: ms-authentication-server

In my gateway server configuration I have:

pom.xml `

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        <version>4.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>       
</dependencies>

`

application.yml

server:
  port: 8085
spring:
  application:
    name: ms-gateway-server
  cloud:
    gateway:
      routes:
        - id: ms-authentication-server
          uri: lb://ms-authentication-server
          predicates:
            - Path=/api/v1/**
          filters:
            - StripPrefix=2
    loadbalancer:
      ribbon:
        enabled: false

eureka:
  client:
    registerWithEureka: true
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    preferIpAddress: true
    leaseRenewalIntervalInSeconds: 10
    leaseExpirationDurationInSeconds: 30

My eureka server looks like this: Eureka server

The ms-authentication-server is working when I use its url direcly, but across gateway server It's not working.

I tried changing microservice name (lb://microservice) and use http://localhost... instead, and It's working.

I'm using:

  1. Spring Boot 3.2.1
  2. Spring cloud 4.1.0 (2023.0.0)

Eureka console is showing nothing related to this error.

eureka console [1]: https://i.stack.imgur.com/hvEVD.png

Eureka server pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.1</version>
    <relativePath/>
</parent>
<groupId>com.cristhianvg</groupId>
<artifactId>eureka-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>eureka-server</name>
<description>Demo project for Spring Boot</description>
<properties>
    <java.version>17</java.version>
    <spring-cloud.version>2023.0.0</spring-cloud.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        <version>4.1.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

FIX Problem was that I was trying to connect a microservice which is using context path, I update that part and It works.

1

There are 1 best solutions below

0
user3876380 On

eureka: client: fetchRegistry: false

modify

eureka: client: fetchRegistry: true