springcloud gateway根据服务名称进行路由失败There was an unexpected error (type=Service Unavailable, status=503)

发布时间 2023-04-12 11:21:38作者: 午夜·bicycle

出现错误,如下图:

解决办法:
检查自己的yaml文件:

server:
  port: 88
spring:
  application:
    name: applicationName
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848

    gateway:
#      开启服务发现路由(不开启跨域问题可能无法解决)
      discovery:
        locator:
          enabled: true

      routes:
        - id: applicationName
          uri: lb://applicationName    
          predicates:
            - Path=/keyword/**
  main:
    web-application-type: reactive

如果确定yaml文件是正确的,那就查看自己是否存在loadbalancer依赖,作用是用来负载均衡

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

最后重启gateway就可以解决了。

本文作者:just1t

本文链接:https://www.cnblogs.com/just1t/p/17002830.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。