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

出现错误,如下图:

解决办法:
检查自己的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就可以解决了。

posted @ 2022-12-24 13:59  just1t  阅读(696)  评论(1编辑  收藏  举报