SpringCloudAlibaba-整合gateway(五)

目录地址:

SpringCloudAlibaba整合-CSDN博客

gateway作为网关,是一个单独的模块

1.添加依赖

XML 复制代码
<!-- SpringCloud Alibaba Nacos -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

<!--gateway-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!--gateway使用lb,必须要这个依赖-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>

2.启动类添加注解,开启nacos配置

3.添加bootstrap文件

XML 复制代码
server:
  port: 8084
# Spring
spring:
  application:
    # 应用名称
    name: my-gateway
  profiles:
    active: gateway-test
  cloud:
    #nacos
    nacos:
      discovery:
        # 服务注册地址
        server-addr: 127.0.0.1:8848
        namespace: fcfd084d-dea1-4a49-922b-2fa4d4e70dd8
        group: dev
    gateway:
      discovery:
        locator:
          #开启注册中心路由功能
          #是否与服务发现组件进行结合,通过serviceId转发到具体的服务实例。默认为false,设为true便开启通过服务中心的自动根据 serviceId 创建路由的功能
          enabled: true
      routes:
        - id: order-service
          uri: lb://my-order
#          uri: http://127.0.0.1:8090/
          predicates:
            - Path=/order/**
          filters:
            - StripPrefix=1 #会截取test从url中删除

4.启动gateway服务,此时用8084端口访问接口 http://127.0.0.1:8084/order/getUserById 访问成功

相关推荐
洛克大航海19 小时前
9-SpringCloud-服务网关 Gateway-高级特性之 Filter-1
spring·spring cloud·gateway·filter
yangmf20402 天前
如何使用 INFINI Gateway 增量迁移 ES 数据
大数据·数据库·elasticsearch·搜索引擎·gateway
非凡的世界3 天前
ThinkPHP6 集成TCP长连接 GatewayWorker
网络·网络协议·tcp/ip·gateway·thinkphp·worker·workman
戮戮3 天前
一次深入排查:Spring Cloud Gateway TCP 连接复用导致 K8s 负载均衡失效
tcp/ip·spring cloud·kubernetes·gateway·负载均衡·netty
洛克大航海4 天前
7-SpringCloud-服务网关 Gateway-高级特性 Route
java·spring cloud·gateway·route
阿Y加油吧6 天前
微服务——day02
springcloud
AWS官方合作商8 天前
在AWS S3上动态自定义图片尺寸:Lambda + API Gateway无服务器解决方案
serverless·gateway·aws
青鱼入云9 天前
对比nginx、kong、apisix、zuul、gateway网关
nginx·gateway·kong
1.01^100011 天前
[3-03-01].第07节:搭建服务 - 服务重构cloud-consumer-ocommon
springcloud
唐僧洗头爱飘柔952712 天前
【SpringCloud(6)】Gateway路由网关;zuul路由;gateway实现原理和架构概念;gateway工作流程;静态转发配置
spring·spring cloud·架构·gateway·请求转发·服务降级·服务雪崩