SpringCloud-Zuul简单使用
引入依赖(注意版本)
spring-cloud-dependencies、spring-cloud-starter-netflix-eureka-client、spring-cloud-starter-netflix-zuul、spring-cloud-starter-actuator、spring-boot-test-starter
引入版本管理依赖
spring-cloud-dependencies
开启代理
@EnableDiscoveryClient
@EnableZuulProxy
配置文件
spring.application.name: hellp-client-zuul
spring.port: 8080
eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/
#匹配url 请求到该网关的所有hello下链接转发到对应服务
zuul.routes.hello.path: /hello/**
#匹配上面url的转发到对应注册中心的hello-eureka-client应用服务
zuul.routes.hello.serviceId: hello-eureka-client
zuul.routes.data.path: /data/**
zuul.routes.data.serviceId: data-eureka-client
本文介绍如何在SpringCloud环境中使用Zuul作为API网关,包括依赖引入、版本管理、启用代理及配置文件设置。通过具体示例,演示如何将不同URL路径映射到对应的服务实例。
168万+

被折叠的 条评论
为什么被折叠?



