解决gateway配合nacos路由报错:Unable to find instance for XXX问题
作者:xiaomu_a
这篇文章主要介绍了解决gateway配合nacos路由报错:Unable to find instance for XXX问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
gateway配合nacos路由报错:Unable to find instance for XXX
gateway配合nacos 找不到服务的问题
nacos版本: 1.1.4 spring-boot版本: 2.5.2 spring-cloud版本: 2020.0.3 spring-cloud-alibaba版本: 2021.1
- gateway网关pom.xml
<dependencies> <!-- gateway --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> </dependency> <!-- nacos注册中心 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> </dependencies>
- api服务pom.xml
<dependencies> <!-- web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- nacos注册中心 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> </dependencies>
- nacos:
浏览器访问
解决方案
找了很多资料,终于找到说Spring Cloud2020移除了Ribbon,加入依赖后成功解决问题:
<!-- Spring Cloud2020移除了Ribbon,导致gateway路由时报错503:找不到服务 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> </dependency>
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。