SpringCloud 微服务 配置zuul网关案例

项目基于上一篇博客的项目
新建model zuul
zuul的目录结构如下
在这里插入图片描述在zuul的pom配置如下

	<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

        </dependency>
    </dependencies>

zuul的application配置如下

server:
  port: 8087

spring:
  application:
    name: zuul

eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:10086/eureka

zuul:
  routes:
    provider: /provider/**
    consumer: /consumer/**
  prefix: /api

zuul的启动类如下

package aom.com;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

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

运行启动类后,可以看到控制中心包含zuul了
在这里插入图片描述

测试consumer
在这里插入图片描述
测试provider
在这里插入图片描述代码已上传GitHub

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页