spring cloud gateway网关路由分配代码实例解析
作者:王东波 时间:2021-06-09 02:54:08
这篇文章主要介绍了spring cloud gateway网关路由分配代码实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
1, 基于父工程,新建一个模块
2,pom文件添加依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
3,添加配置
server:
port: 9091
spring:
application:
name: gateway3
cloud:
nacos:
discovery:
server-addr: localhost:8848
namespace: c22e5019-0bee-43b1-b80b-fc0b9d847501
register-enabled: false
gateway:
routes:
- id: demo_route
uri: lb://demo
predicates:
- Path=/demo/**
- id: demo2_test
uri: lb://demo2
predicates:
- Path=/user/**
4,编写启动类
@SpringBootApplication
@EnableDiscoveryClient
public class Gateway3Application {
public static void main(String[] args) {
SpringApplication.run(Gateway3Application.class, args);
}
}
5,访问http://localhost:9091/demo或http://localhost:9091/demo2路由到指定的服务
来源:https://www.cnblogs.com/dongbo/p/12222700.html
标签:spring,cloud,gateway,网关
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MyBatis中map的应用与模糊查询实现代码
2021-09-02 18:27:14
Java多线程下载文件实现案例详解
2023-11-09 14:02:36
![](https://img.aspxhome.com/file/2023/4/59414_0s.png)
如何使用MybatisPlus快速进行增删改查详解
2023-11-03 06:58:13
![](https://img.aspxhome.com/file/2023/1/58741_0s.png)
springboot异常处理的基本规范
2023-11-23 15:48:19
![](https://img.aspxhome.com/file/2023/8/59488_0s.png)
Spring Boot自动注入的原理分析
2023-03-29 04:19:44
Android实现摇一摇功能
2023-07-23 20:21:11
java客户端Jedis操作Redis Sentinel 连接池的实现方法
2023-08-19 10:55:19
Java代码实现循环队列的示例代码
2023-11-23 23:51:25
![](https://img.aspxhome.com/file/2023/7/59927_0s.jpg)
详解Java异常处理中finally子句的运用
2023-11-29 10:10:30
Java适配器模式_动力节点Java学院整理
2021-09-06 10:50:53
![](https://img.aspxhome.com/file/2023/6/65636_0s.jpg)
Tomcat 实现WebSocket详细介绍
2023-08-12 21:22:11
![](https://img.aspxhome.com/file/2023/0/58150_0s.png)
synchronized背后的monitor锁实现详解
2023-07-31 08:14:10
java中多个@Scheduled定时器不执行的解决方法
2023-03-19 02:32:34
java使用dom4j操作xml示例代码
2022-03-21 18:28:38
java跟踪执行的sql语句示例分享
2022-07-30 20:13:18
SpringBoot+JSON+AJAX+ECharts+Fiddler实现前后端分离开发可视化
2021-11-12 14:49:17
![](https://img.aspxhome.com/file/2023/2/61562_0s.png)
SpringBoot结合JWT登录权限控制的实现
2023-10-06 04:54:22
mybatis根据表逆向自动化生成代码的实现
2023-03-12 15:39:02
![](https://img.aspxhome.com/file/2023/9/61079_0s.png)
Spring Boot使用Allatori代码混淆的方法
2023-11-24 16:34:55
![](https://img.aspxhome.com/file/2023/0/59080_0s.jpg)
Spring探秘之如何妙用BeanPostProcessor
2021-07-01 22:41:46