SpringCloud Alibaba网关gateway请求后报错503错误

2022-03-21 711点热度 0人点赞 0条评论

使用阿里巴巴的SpringCloud的网关组件(Gateway),配置好application.yml,最基础的配置如下:

spring:
  application:
    name: test-gateway
  cloud:
    nacos:
      discovery:
        server-addr: 1.2.3.4:8848
        username: nacos
        password: nacos
    gateway:
      discovery:
        locator:
          enabled: true
      routes:
        - id: service_complaint_router
          uri: lb://service-complaint
          predicates:
            - Path=/complaint/**

另一个微服务已经启动好,直接访问改微服务是可以返回请求的(service-complaint的地址,例如http://127.0.0.1:8081/complaint/test)

使用gateway后,应该是请求gateway的端口(http://127.0.0.1:9090/complaint/test)

发现请求后,页面报503错误

There was an unexpected error (type=Service Unavailable, status=503).

解决方法

原因是pom.xml没有加lbLoadBalance)相关的依赖,需要加lb(相关的依赖,如下:

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

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论