spring cloud 2020 gateway Error 503 [How to Solve]

POM file dependency

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <!--gateway fhadmin.org-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
        <version>3.0.2</version>
    </dependency>
    <!--spring-boot fhadmin.org-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

The related dependencies of Nacos I added in the parent component are as follows:

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    <version>${nacos.version}</version>
</dependency>
<!--alibaba fhadmin.org-->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    <version>${nacos.version}</version>
</dependency>

The version of Nacos is as follows:

<properties>
    <nacos.version>2021.1</nacos.version>
</properties>

The application.yml file of gateway is configured as follows:

#fhadmin.org
server:
  port: 9040

spring:
  application:
    name: gateway
  cloud:
    gateway:
      routes:
        - id: consumer
          uri: lb://consumer
          #          uri: http://localhost:9010
          predicates:
            - Path=/**
    nacos:
      discovery:
        server-addr: localhost:8848
        metadata:
          preserved.heart.beat.interval: 3 
          preserved.heart.beat.timeout: 6 
          preserved.ip.delete.timeout: 9 

When I pass URI: http://localhost:9010 When calling a service, it can be called, but when I use URI LB:// consumer, I cannot call the service, and an error 503 is reported

The solution is:
Add feign dependency.

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
        <version>3.0.2</version>
    </dependency>

    <!--fegin fhadmin.cn-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
        <version>3.0.2</version>
    </dependency>
    <!-- Feign Client for loadBalancing -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-loadbalancer</artifactId>
        <version>3.0.2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

Guess the reason: Nacos is compatible with feign. Feign integrates ribbon and realizes load balancing by default; Maybe Nacos is not compatible with the ribbon of springcloud gateway.

Read More: