当前位置: 首页 > news >正文

[ Spring ] Spring Cloud Gateway 2025 Comprehensive Overview

文章目录

          • Spring Gateway Architecture
          • Project Level Dependency
          • Service Center
          • Service Provider
          • Gateway Service
          • Launch All Service

Spring Gateway Architecture
  • Service Center : register and find service provider
  • Service Provider : programs that provide actual service
  • Gateway Service : dispatch client requests to service providers

data flow : request => gateway => service center => service provider

Project Level Dependency
pluginManagement {repositories {gradlePluginPortal()google()mavenCentral()}
}dependencyResolutionManagement {repositoriesMode = RepositoriesMode.PREFER_SETTINGSrepositories {gradlePluginPortal()google()mavenCentral()}
}buildscript {repositories {gradlePluginPortal()google()mavenCentral()}
}plugins {id("org.jetbrains.kotlin.jvm") version "2.0.21" apply falseid("org.jetbrains.kotlin.kapt") version "2.0.21" apply falseid("org.jetbrains.kotlin.plugin.spring") version "2.0.21" apply falseid("org.springframework.boot") version "3.4.1" apply false
}include("eureka-server")
include("spring-gateway-service")
include("spring-gateway-provider")
Service Center
plugins {id("org.jetbrains.kotlin.jvm")id("org.jetbrains.kotlin.kapt")id("org.jetbrains.kotlin.plugin.spring")id("org.springframework.boot")
}java {toolchain {languageVersion = JavaLanguageVersion.of(17)}
}dependencies {// commonsapi("io.github.hellogoogle2000:kotlin-commons:1.0.19")// kotlinapi("org.jetbrains.kotlin:kotlin-reflect:2.0.21")// springapi("org.springframework.boot:spring-boot-starter:3.4.1")api("org.springframework.boot:spring-boot-starter-web:3.4.1")api("org.springframework.boot:spring-boot-devtools:3.4.1")// eurekaapi("org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:4.2.0")
}
# service
server.port=10001
spring.application.name=eureka-server
# eureka
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://localhost:10001/eureka/
package x.spring.helloimport org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer@EnableEurekaServer
@SpringBootApplication
class EurekaServerApplicationfun main(args: Array<String>) {runApplication<EurekaServerApplication>(*args)
}
Service Provider
plugins {id("org.jetbrains.kotlin.jvm")id("org.jetbrains.kotlin.kapt")id("org.jetbrains.kotlin.plugin.spring")id("org.springframework.boot")
}java {toolchain {languageVersion = JavaLanguageVersion.of(17)}
}dependencies {// commonsapi("io.github.hellogoogle2000:kotlin-commons:1.0.19")// kotlinapi("org.jetbrains.kotlin:kotlin-reflect:2.0.21")// springapi("org.springframework.boot:spring-boot-starter:3.4.1")api("org.springframework.boot:spring-boot-starter-web:3.4.1")// eurekaapi("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:4.2.0")
}
# service
server.port=10003
spring.application.name=gateway-provider
# eureka
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://localhost:10001/eureka/
package x.spring.helloimport org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication@SpringBootApplication
class GatewayProviderApplicationfun main(args: Array<String>) {runApplication<GatewayProviderApplication>(*args)
}
package x.spring.hello.controllerimport org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController@RestController
class ConfigController {@GetMapping("/config/{key}")fun index(@PathVariable("key") key: String): String {return "config service provider on 10003 key=$key"}
}
Gateway Service
plugins {id("org.jetbrains.kotlin.jvm")id("org.jetbrains.kotlin.kapt")id("org.jetbrains.kotlin.plugin.spring")id("org.springframework.boot")
}java {toolchain {languageVersion = JavaLanguageVersion.of(17)}
}dependencies {val springBootVersion = "3.4.1"val springCloudVersion = "4.2.0"// commonsapi("io.github.hellogoogle2000:kotlin-commons:1.0.19")// kotlinapi("org.jetbrains.kotlin:kotlin-reflect:2.0.21")// springapi("org.springframework.boot:spring-boot-starter:$springBootVersion")api("org.springframework.boot:spring-boot-devtools:$springBootVersion")api("org.springframework.cloud:spring-cloud-starter-bootstrap:$springCloudVersion")// spring cloud gatewayapi("org.springframework.boot:spring-boot-starter-webflux:$springBootVersion")api("org.springframework.cloud:spring-cloud-starter-gateway:$springCloudVersion")api("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:$springCloudVersion")api("javax.servlet:javax.servlet-api:4.0.1")
}
# service
server.port=10002
spring.application.name=gateway-service
# eureka
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://localhost:10001/eureka/
# gateway
spring.cloud.gateway.routes[0].id=config
spring.cloud.gateway.routes[0].uri=lb://gateway-provider
spring.cloud.gateway.routes[0].predicates[0]=Path=/config/**
# http://localhost:10002/config/name => http://localhost:10003/config/name
package x.spring.helloimport org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication@SpringBootApplication
class GatewayServiceApplicationfun main(args: Array<String>) {runApplication<GatewayServiceApplication>(*args)
}
package x.spring.hello.componentimport org.springframework.cloud.gateway.route.RouteLocator
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder
import org.springframework.cloud.gateway.route.builder.filters
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration@Configuration
class GatewayRule {@Beanfun rule(builder: RouteLocatorBuilder): RouteLocator {val routes = builder.routes()// http://localhost:10002/github/byteflys => https://github.com/byteflysroutes.route("csdn") { route ->route.filters {rewritePath("/github/(?<variable>.*)", "/\${variable}")}route.path("/github/**").uri("https://github.com/")}return routes.build()}
}
Launch All Service
http://localhost:10001
http://localhost:10003/config/name
http://localhost:10002/config/name => http://localhost:10003/config/name
http://localhost:10002/github/byteflys => https://github.com/byteflys

相关文章:

[ Spring ] Spring Cloud Gateway 2025 Comprehensive Overview

文章目录 Spring Gateway ArchitectureProject Level DependencyService CenterService ProviderGateway ServiceLaunch All Service Spring Gateway Architecture Service Center : register and find service providerService Provider : programs that provide actual serv…...

【项目初始化】自定义异常处理

我们在项目初始化的工作之一就是要自定义异常处理&#xff0c;用来处理项目中出现的各种异常&#xff0c;如业务异常、系统异常等等。 这些属于项目的通用基础代码&#xff0c;在任何后端中都可以复用。 1. 自定义错误码 自定义错误码&#xff0c;对错误进行收敛&#xff0c;…...

Windows10安装MySQL找不到MSVCR120.dll和MSVCP120.dll问题解决

个人博客地址&#xff1a;Windows10安装MySQL找不到MSVCR120.dll和MSVCP120.dll问题解决 | 一张假钞的真实世界 msvcp120.dll、msvcr120.dll、vcomp120.dll属于VC2013版中的动态链接库&#xff0c;如果丢失重新安装VC2013即可。下载地址&#xff1a;https://www.microsoft.com…...

【嵌入式】总结——Linux驱动开发(三)

鸽了半年&#xff0c;几乎全忘了&#xff0c;幸亏前面还有两篇总结。出于快速体验嵌入式linux的目的&#xff0c;本篇与前两篇一样&#xff0c;重点在于使用、快速体验&#xff0c;uboot、linux、根文件系统不作深入理解&#xff0c;能用就行。 重新梳理一下脉络&#xff0c;本…...

计算机图形学:实验三 光照与阴影

一、程序功能设计 设置了一个3D渲染场景&#xff0c;支持通过键盘和鼠标控制交互&#xff0c;能够动态调整光源位置、物体材质参数等&#xff0c;具有光照、阴影和材质效果的场景渲染。 OpenGL物体渲染和设置 创建3D物体&#xff1a;代码中通过 openGLObject 结构体表示一个…...

「 机器人 」扑翼飞行器混合控制策略缺点浅谈

前言 将基于模型的控制与强化学习策略融合在扑翼飞行器中,虽然能够兼顾系统稳定性与极限机动能力,但也面临了更高的系统复杂性、对硬件算力与可靠性的额外要求,以及难以回避的能量效率等方面挑战。以下从四个方面进行归纳与分析。 1. 系统复杂性增加 1.1 两种控制方法的并存…...

蓝桥杯算法日常|c\c++常用竞赛函数总结备用

一、字符处理相关函数 大小写判断函数 islower和isupper&#xff1a;是C标准库中的字符分类函数&#xff0c;用于检查一个字符是否为小写字母或大写字母&#xff0c;需包含头文件cctype.h&#xff08;也可用万能头文件包含&#xff09;。返回布尔类型值。例如&#xff1a; #…...

每日十题八股-2025年1月24日

1.面试官&#xff1a;Kafka 百万消息积压如何处理&#xff1f; 2.面试官&#xff1a;最多一次、至少一次和正好一次有什么区别? 3.面试官&#xff1a;你项目是怎么存密码的? 4.面试官&#xff1a;如何设计一个分布式ID&#xff1f; 5.面试官&#xff1a;单点登录是怎么工作的…...

tomcat的accept-count、max-connections、max-threads三个参数的含义

tomcat的accept-count、max-connections、max-threads三个参数的含义 tomcat的accept-count、max-connections、max-threads三个参数的含义 max-connections&#xff1a;最大连接数 最大连接数是指&#xff0c;同一时刻&#xff0c;能够连接的最大请求数 需要注意的是&#x…...

【无标题】mysql python 连接

coding:utf8 import os import pymysql import yaml from common.log import logger class Mysql: # 处理.sql备份文件为SQL语句 def __read_sql_file(self,file_path): # 打开SQL文件到f sql_list = [] with open(file_path, ‘r’, encoding=‘utf8’) as f: # 逐行读取和…...

linux naive代理设置

naive linux客户端 Release v132.0.6834.79-2 klzgrad/naiveproxy GitHub Client setup Run ./naive with the following config.json to get a SOCKS5 proxy at local port 1080. {"listen": "socks://127.0.0.1:1080","proxy": "htt…...

[STM32 - 野火] - - - 固件库学习笔记 - - -十一.电源管理系统

一、电源管理系统简介 电源管理系统是STM32硬件设计和系统运行的基础&#xff0c;它不仅为芯片本身提供稳定的电源&#xff0c;还通过多种电源管理功能优化功耗、延长电池寿命&#xff0c;并确保系统的可靠性和稳定性。 二、电源监控器 作用&#xff1a;保证STM32芯片工作在…...

DBO优化最近邻分类预测matlab

蜣螂优化算法&#xff08;Dung Beetle Optimizer&#xff0c;简称 DBO&#xff09;作为一种新兴的群智能优化算法&#xff0c;于 2022 年末被提出&#xff0c;其灵感主要来源于蜣螂的滚球、跳舞、觅食、偷窃以及繁殖等行为。 本次使用的数据为 Excel 格式的分类数据集。该数据…...

【深入理解FFMPEG】命令行阅读笔记

这里写自定义目录标题 第三章 FFmpeg工具使用基础3.1 ffmpeg常用命令3.1.13.1.3 转码流程 3.2 ffprobe 常用命令3.2.1 ffprobe常用参数3.2.2 ffprobe 使用示例 3.3 ffplay常用命令3.3.1 ffplay常用参数3.3.2 ffplay高级参数3.3.4 ffplay快捷键 第4章 封装与解封装4.1 视频文件转…...

图形化数据报文转换映射工具

目录 概要整体架构流程技术名词解释技术细节小结 概要 在当今数字化时代&#xff0c;数据的处理和分析是企业、科研机构以及各类组织日常运营的核心环节。数据来源广泛&#xff0c;格式多样&#xff0c;常见的数据格式包括XML&#xff08;可扩展标记语言&#xff09;和JSON&a…...

智能体0门槛开发

分享一个智能体开发流程。 2025 年啊&#xff0c;好多专家还有行业报告都觉得这是智能体&#xff08;AI Agent&#xff09;应用的头一年。相关的应用在商业、工业、消费等好些领域都到了关键的时候&#xff0c;这意味着从实验室走向大规模实际应用的重要转变。而且呢&#xff0…...

ssh密钥登录GitHub时一直提示“Error: Permission denied (publickey)”

起因 环境&#xff1a;Windows10 背景&#xff1a;之前就是按照官方说明创建个rsa密钥&#xff0c;在git后台添加上&#xff0c;就行了&#xff0c;近期怎么添加怎么失败&#xff0c;总是“Error: Permission denied (publickey)”的提示&#xff01; 尝试 各种尝试&#xf…...

mapbox加载geojson,鼠标移入改变颜色,设置样式以及vue中的使用

全国地图json数据下载地址 目录 html加载全部代码 方式一&#xff1a;使用html方式加载geojson 1. 初始化地图 2. 加载geojson数据 设置geojson图层样式&#xff0c;设置type加载数据类型 设置线条 鼠标移入改变颜色&#xff0c;设置图层属性&#xff0c;此处是fill-extru…...

考研机试题:打印日期

描述 给出年分m和一年中的第n天&#xff0c;算出第n天是几月几号。 输入描述: 输入包括两个整数y(1<y<3000)&#xff0c;n(1<n<366)。 输出描述: 可能有多组测试数据&#xff0c;对于每组数据&#xff0c; 按 yyyy-mm-dd的格式将输入中对应的日期打印出来。 …...

OpenHarmonyOS 3.2 编译生成的hap和app文件的名称如何配置追加版本号?

找了一圈发现官方的文档都是最新的&#xff0c;3.2很多API都不支持&#xff0c;比如获取OhosAppContext&#xff0c;通过OhosAppContext来获取应用版本号&#xff0c;最终是通过读取app.json5的文件内容来读取版本号&#xff0c;最终修改entry下的hvigorfile.ts如下&#xff0c…...

【openwrt】openwrt odhcpd配置介绍

odhcpd odhcpd是一个嵌入式DHCP/DHCPv6/RA服务器和NDP中继的进程,odhcpd是一个守护进程,用于服务和中继IP管理协议,以配置客户端和下游路由器。它试图遵循IPv6家用路由器的RFC 6204要求。odhcpd为DHCP、RA、无状态SLAAC和有状态DHCPv6、前缀委派提供服务器服务,并可用于在没…...

基于神经网络的视频编码NNVC(1):帧内预测

在H.266/VVC发布后&#xff0c;基于传统编码框架提升压缩率越来越难&#xff0c;随着深度学习的发展&#xff0c;研究人员开始尝试将神经网络引入编码器。为此&#xff0c;JVET工作组在2020年成立AHG11小组来专门进行基于神经网络的视频编码的研究。 为了方便研究&#xff0c;工…...

Android开发,待办事项提醒App的设计与实现

文章目录 1. 研究目的2. 主要内容3. 运行效果图4. 涉及到的技术点5. 开发环境6. 关于作者其它项目视频教程介绍 1. 研究目的 当今,随着时代的发展和计算机的普及,人们开始利用网络来记录并管理日常的事务,时下这方面的软件数不胜数。各种日程管理软件就是将每天的工作和事务安…...

豆瓣Top250电影的数据采集与可视化分析(scrapy+mysql+matplotlib)

文章目录 豆瓣Top250电影的数据采集与可视化分析(scrapy+mysql+matplotlib)写在前面数据采集(Visual Studio Code+Navicat)1.观察网页信息2.编写Scrapy代码(Visual Studio Code)2.1 创建Scrapy项目`doubanProject`2.2 创建爬虫脚本`douban.py`2.3 修改`douban.py`的代码2…...

MySQL索引——让查询飞起来

文章目录 索引是什么&#xff1f;&#xff1f;硬件理解MySQL与存储 MySQL 与磁盘交互基本单位索引的理解B vs B聚簇索引 VS 非聚簇索引索引操作创建主键索引唯一索引的创建普通索引的创建全文索引的创建查询索引删除索引 在现代数据库应用中&#xff0c;查询性能是决定系统响应…...

Springboot集成Elasticsearch8.0(ES)版本,采用JAVA Client方式进行连接和实现CRUD操作

本文章介绍了 springboot t集成Elasticsearch8.0(ES)版本,如何通过 AVA Client方式进行连接和实现CRUD操作 在ES7.15版本之后,ES官方将高级客户端 RestHighLevelClient标记为弃用状态。同时推出了全新的 Java API客户端 Elasticsearch Java API Client,该客户端也将在 Ela…...

【Linux】APT 密钥管理迁移指南:有效解决 apt-key 弃用警告

引言 随着 Debian 11 和 Ubuntu 22.04 版本的推出&#xff0c;APT 的密钥管理方式发生了重大的变化。apt-key 命令被正式弃用&#xff0c;新的密钥管理机制要求使用 /etc/apt/keyrings/ 或 /etc/apt/trusted.gpg.d/ 来存储和管理密钥。这一变化对管理员和普通用户来说至关重要…...

洛谷P1143 进制转换

题目链接&#xff1a;P1143 进制转换 - 洛谷 | 计算机科学教育新生态 题目难度&#xff1a;普及— 解题思路&#xff1a;本题先将输入的数转为10进制&#xff0c;然后取模&#xff0c;最后倒着输出就好了&#xff0c;最后直接上代码 #include<bits/stdc.h> using namespa…...

99.12 金融难点通俗解释:毛利率

目录 0. 承前1. 简述2. 比喻&#xff1a;冰淇淋店赚钱2.1 第一步&#xff1a;准备材料2.2 第二步&#xff1a;卖冰淇淋2.3 第三步&#xff1a;计算毛利率 3. 生活中的例子3.1 好的毛利率3.2 一般的毛利率3.3 差的毛利率 4. 小朋友要注意4.1 毛利率高不一定好4.2 毛利率低不一定…...

HUMANITY’S LAST EXAM (HLE) 综述:人工智能领域的“最终考试”

论文地址&#xff1a;Humanity’s Last Exam 1. 背景与动机 随着大型语言模型&#xff08;LLMs&#xff09;能力的飞速发展&#xff0c;其在数学、编程、生物等领域的任务表现已超越人类。为了系统地衡量这些能力&#xff0c;LLMs 需要接受基准测试&#xff08;Benchmarks&…...