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

Spring Cloud之三 网关 Gateway

1:Intellij 新建项目 spring-cloud-gateway

2:pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>cn.tigee</groupId><artifactId>spring-cloud-gateway</artifactId><version>1.0-SNAPSHOT</version><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-parent</artifactId><version>2023.0.3</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><!-- 引入 Spring Cloud Gateway 相关依赖,使用它作为网关,并实现对其的自动配置 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-web</artifactId>-->
<!--        </dependency>--></dependencies>
</project>

3:application.yml

server:port: 7101servlet:context-path: /
spring:application:name: spring-cloud-gatewaycloud:gateway:discovery:locator:enabled: true   #开启Eureka服务发现lower-case-service-id: true
eureka:client:service-url:defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}instance:prefer-ip-address: true

4:启动类

package tigee;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@SpringBootApplication
@EnableDiscoveryClient
public class ApplicationMain {static final Logger logger = LoggerFactory.getLogger(ApplicationMain.class);public static void main(String[] args) {logger.debug("服务启动..start......");SpringApplication.run(ApplicationMain.class, args);logger.debug("服务启动..end......");}}

3:启动看 注册中心

4:请求接口

http://localhost:7101/user-service/hello?name=12

 5:user-service 动多个端口

 

 再请求  localhost:7101/user-service/hello?name=12

 6:结果 是 端口 轮询显示

http://www.lryc.cn/news/437951.html

相关文章:

  • Linux 进程1
  • LeetCode: 2552. 统计上升四元组 动态规划 时间复杂度O(n*n)
  • Unity 编辑器设置中文
  • springboot-创建连接池
  • matlab绘制不同区域不同色彩的图,并显示数据(代码)
  • Docker Desktop 的安装与汉化指南
  • 前端form表单+ifarme方式实现大文件下载
  • Leetcode面试经典150题-141.环形链表
  • sh文件执行提示语法错误: 未预期的文件结尾
  • 基于SpringBoot的甜品店管理系统
  • 动态规划-不同的子序列
  • 如何通过OceanBase的多级弹性扩缩容能力应对业务洪峰
  • D - 1D Country(AtCoder Beginner Contest 371)
  • 怎么很多张图片拼接成一张?试试这几种图片拼接方法!
  • Python实现优化的分水岭算法
  • 智慧交通基于yolov8的行人车辆检测计数系统python源码+onnx模型+精美GUI界面
  • Linux开发工具的使用
  • 【devops】devops-git之介绍以及日常使用
  • 012复杂度07leetcode
  • 4.网络编程
  • OpenCV GUI常用函数详解
  • Tuxera NTFS for Mac破解版下载 Tuxera NTFS for Mac2023激活码 mac电脑ntfs磁盘软件
  • oceanbase(ob)基于备份集搭建备租户方式
  • Javase复习day21算法、arrays、Lamdba表达式
  • 移动硬盘无法读取?别慌!这些方法助你恢复数据!
  • Java集合面试(上)
  • Python画笔案例-046 绘制小红伞
  • 使用 .NET 6 构建跨平台 Worker Service 服务:跨越平台的 C# 服务开发——解决Windows服务跨平台问题
  • terminator-gnome
  • 7.测试用例设计方法 + Bug