spring cloud 2020 gateway 报错503
POM文件依赖
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starterartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-gatewayartifactId>
<version>3.0.2version>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
dependencies>
我在父组件中加入的nacos的相关依赖如下:
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-configartifactId>
<version>${nacos.version}version>
dependency>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
<version>${nacos.version}version>
dependency>
nacos的版本如下:
<properties>
<nacos.version>2021.1nacos.version>
properties>
gateway的application.yml文件配置如下:
#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 #心跳暂停。时间单位:秒。 即服务端6秒收不到客户端心跳,会将该客户端注册的实例设为不健康:
preserved.ip.delete.timeout: 9 #Ip删除超时。时间单位:秒。即服务端9秒收不到客户端心跳,会将该客户端注册的实例删除:
当我通过uri: http://localhost:9010去调用服务时,是可以调用的,但是当我用uri lb://consumer时就无法调用服务,报错503.
解决办法是:
加入feign依赖。
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starterartifactId>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-gatewayartifactId>
<version>3.0.2version>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-openfeignartifactId>
<version>3.0.2version>
dependency>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-loadbalancerartifactId>
<version>3.0.2version>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
dependencies>
猜测原因:nacos兼容feign,feign集成ribbon,默认实现负载均衡;或许是nacos不兼容springcloud gateway自带的ribbon。
www.somanba.cn |
www.zuowenge.cn |
www.awaedu.comhttp://www.awaedu.com/ |