springcloudgateway 默认转发不生效

配置文件配置了自动转发

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依赖


    org.springframework.cloud
    spring-cloud-starter-loadbalancer

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

你可能感兴趣的:(springcloud,gateway,ribbon,loadbalancer)