美文网首页
Spring Cloud 05 -- 网关 Zuul

Spring Cloud 05 -- 网关 Zuul

作者: 半碗鱼汤 | 来源:发表于2019-08-12 11:10 被阅读0次

一、说明

在 Eureka Client 的基础上,将其改造成网关组件 Zuul

二、添加依赖

        <!-- zuul -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>

三、启动类添加注解 @EnableZuulProxy

四、修改配置文件 application.yml

添加以下内容

# 网关相关配置
zuul:
  routes:
    client01:
      path: /client01/**
      serviceId: client01
    client02:
      path: /client02/**
      serviceId: client02

完整配置文件如下

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
    prefer-ip-address: true
server:
  port: 8769
spring:
  application:
    name: zuul-gateway
# 网关相关配置
zuul:
  routes:
    client01:
      path: /client01/**
      serviceId: client01
    client02:
      path: /client02/**
      serviceId: client02

五、启动 eureka server、client01、clent02、zuul gateway

eureka server

访问 http://localhost:8769/client01/hello

通过网关 zuul 访问 client01

访问 http://localhost:8769/client02/hello

通过网关 zuul 访问 client02

相关文章

网友评论

      本文标题:Spring Cloud 05 -- 网关 Zuul

      本文链接:https://www.haomeiwen.com/subject/lpuyjctx.html