当前位置:首页 > 编程笔记 > 正文
已解决

springcloudgateway 默认转发不生效

来自网友在路上 130830提问 提问时间:2023-09-27 06:23:55阅读次数: 30

最佳答案 问答题库308位专家为你答疑解惑

配置文件配置了自动转发

spring.cloud.gateway.discovery.locator.enabled= true   

但是用微服务路径访问时一直报503

[fa9cc893-1] There was an unexpected error (type=Service Unavailable, status=503).

这个503看得我是一头雾水。原因在于这个默认错误页的报错显示不全,需要开启两个配置帮助检查

#输出错误页的异常信息
server.error.include-message=always
#输出错误页的异常栈(开发环境开启,生产环境关闭)
server.error.include-stacktrace=always

开启后看报错内容好多了

[fa9cc893-1] There was an unexpected error (type=Service Unavailable, status=503).
Unable to find instance for user-center
org.springframework.cloud.gateway.support.NotFoundException: 503 SERVICE_UNAVAILABLE "Unable to find instance for user-center"at org.springframework.cloud.gateway.support.NotFoundException.create(NotFoundException.java:45)

报错原因为找不到微服务实例

根据关键词搜索找到这么一篇Sping Cloud Gateway Unable to find instance for_jonhy.luo的博客-CSDN博客

废弃ribbon这个跟我这个有点像,我的spring cloud alibaba版本为2021.0.5.0,spring cloud 版本为2021.0.5
增加loadbalance依赖

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>

重新启动gateway工程,默认转发正常了。

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"springcloudgateway 默认转发不生效":http://eshow365.cn/6-14464-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!