SpringCloud路由网关Zuul

一、什么是网关

  Zuul的主要功能是路由转发和过滤器。路由功能是微服务的一部分,比如/api/user转发到到user服务,/api/shop转发到到shop服务。zuul默认和Ribbon结合实现了负载均衡的功能, 类似于nginx转发。

二、搭建SpringCloud网关

 创建工程service-zuul 目录展示

 1.导入依赖

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

  <dependencyManagement>
    <dependencies>
      <!--springCloud依赖-->
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Greenwich.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

    </dependencies>
  </dependencyManagement>
View Code

 2.application.yml配置文件

 3.ZuulApp启动类

原文地址:https://www.cnblogs.com/mayuan01/p/12071552.html