SpringCloud路由网关Zuul

一、什么是网关

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

二、搭建SpringCloud网关

  2.1 创建工程service-zuul 目录展示

    SpringCloud路由网关Zuul_第1张图片

 

  2.2 导入依赖   

    SpringCloud路由网关Zuul_第2张图片

 
    <dependency>
      <groupId>org.springframework.cloudgroupId>
      <artifactId>spring-cloud-starter-netflix-eureka-serverartifactId>
    dependency>
    <dependency>
      <groupId>org.springframework.cloudgroupId>
      <artifactId>spring-cloud-starter-netflix-zuulartifactId>
    dependency>

  <dependencyManagement>
    <dependencies>
      
      <dependency>
        <groupId>org.springframework.cloudgroupId>
        <artifactId>spring-cloud-dependenciesartifactId>
        <version>Greenwich.RELEASEversion>
        <type>pomtype>
        <scope>importscope>
      dependency>

    dependencies>
  dependencyManagement>

  2.3 application.yml配置文件

    SpringCloud路由网关Zuul_第3张图片

 

   2.4 StartSpringCloudZuul启动类

package com.zn;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@EnableEurekaClient
@SpringBootApplication
@EnableZuulProxy
public class StartSpringCloudZuul {
    public static void main(String[] args) {
        SpringApplication.run(StartSpringCloudZuul.class,args);
    }
}

  2.5 效果展示

    SpringCloud路由网关Zuul_第4张图片

 

 

 

 

你可能感兴趣的:(SpringCloud路由网关Zuul)