使用阿里巴巴的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>
文章评论