将网关注册到"服务中心",实现服务转发
阅读 (838332)
分享
1、将网关注册到"服务中心",实现服务转发
Spring Cloud Gateway提供了一种默认的转发功能,当网关被注册到"服务中心"后,网关会代理"服务中心"转发服务。
1.1、新建工程,添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
1.2、添加配置
spring.application.name=gateway-eureka
server.port=50024
#注册中心地址
eureka.client.register-with-eureka=false
#eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://eureka01:50025/eureka/,http://eureka02:50026//eureka/
#表示是否与"服务中心"的发现组件进行结合
spring.cloud.gateway.discovery.locator.enabled=true
1.3、测试配置
步骤:
1、启动"服务中心"
2、启动服务提供者
3、启动网关工程
4、访问http://localhost:50024/PROVIDER1/hello
需要
登录
才可以提问哦
: