NipGeihou's blog NipGeihou's blog
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档

NipGeihou

我见青山多妩媚,料青山见我应如是
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档
  • 设计模式

  • 开发规范

  • 经验分享

  • 记录

  • 快速开始

  • 笔记

  • 面试题

  • 微服务

    • 项目结构

    • Nacos

    • Gateway

      • Microservice - Spring Cloud Gateway(网关)上手
        • 概述
        • 版本选择
        • 示例
          • 依赖
          • 配置
          • 启动类
        • 常见配置
    • OpenFeign

    • Seata

  • 踩过的坑

  • Java
  • 微服务
  • Gateway
NipGeihou
2022-07-31
目录

Microservice - Spring Cloud Gateway(网关)上手

# 概述

官网:https://spring.io/projects/spring-cloud-gateway

# 版本选择

Spring Cloud Gateway 是基于 Spring Boot,可在 Maven Repository: org.springframework.cloud » spring-cloud-starter-gateway (opens new window) 查看各个版本对 Spring Boot 的版本要求,从而选择适合的版本。

两种方式:

  1. 选择最新版,但可能与父工程的 Spring Boot 不兼容,此时需要单独给网关服务指定 Spring Boot 版本
  2. 选择兼容版本

# 示例

注册中心为 Nacos

# 依赖

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
    <version>${gateway.version}</version>
</dependency>

# 配置

spring:
  application:
    name: gateway-service
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
    gateway:
      discovery:
        locator:
          enabled: true
      routes:
        - id: hello
          uri: lb://hello-service
          predicates:
            - Path=/hello/**
        - id: hi
          uri: lb://hi-service
          predicates:
            - Path=/hi/**

# 启动类

@EnableDiscoveryClient

# 常见配置

  • 跨域配置 (opens new window)
上次更新: 2023/04/17, 23:26:02
Microservice - Nacos
Microservice - OpenFeign

← Microservice - Nacos Microservice - OpenFeign→

最近更新
01
iSCSI服务搭建
05-10
02
磁盘管理与文件系统
05-02
03
网络测试 - iperf3
05-02
更多文章>
Theme by Vdoing | Copyright © 2018-2025 NipGeihou | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式