springcloud gateway + nacos 遇到503错误

pom文件依赖


        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
        
        
        
            org.springframework.cloud
            spring-cloud-starter-gateway
        
    

主类加入服务发现注解

package com.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@EnableDiscoveryClient
@SpringBootApplication
public class GatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }
}

配置yml

server:
  port: 7000
spring:
  application:
    name: service-gateway
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
    gateway:
      discovery:
        locator:
          enabled: true
      routes:
        - id: product_route
          uri: lb://service-product
          predicates:
            - Path=/product-serv/**
          filters:
            - StripPrefix=1

测试

springcloud gateway + nacos 遇到503错误_第1张图片

报503错误,原因是微服务不可获取

解决:加入feign依赖


        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
        
        
        
            org.springframework.cloud
            spring-cloud-starter-openfeign
        
        
        
            org.springframework.cloud
            spring-cloud-loadbalancer
            3.0.2
        
        
        
            org.springframework.cloud
            spring-cloud-starter-gateway
        
    

重启,测试

springcloud gateway + nacos 遇到503错误_第2张图片

猜测原因:nacos兼容feign,feign集成ribbon,默认实现负载均衡;或许是nacos不兼容springcloud-gateway自带的ribbon。

如有错误,欢迎指出。

你可能感兴趣的:(gateway,spring,boot)