栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Gateway

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Gateway

1.简述

网关作为流量的入口,常用功能包括路由转发、权限校验、限流控制等。而 springcloud gateway作为 SpringCloud 官方推出的第二代网关框架,取代了 Zuul 网关。
网关提供 API 全托管服务,丰富的 API 管理功能,辅助企业管理大规模的 API,以降低管理成本和安全风险,包括协议适配、协议转发、安全策略、防刷、流量、监控日志等功能。
Spring Cloud Gateway 旨在提供一种简单而有效的方式来对 API 进行路由,并为他们提供切面,例如:安全性,监控/指标 和弹性等

2.特征

Spring Cloud Gateway 特性:

  • 基于 Spring framework 5、Project Reactor 和 Spring Boot 2.0
  • 能够匹配任何请求属性的路由。
  • 谓词和过滤器特定于路由。
  • 断路器集成。
  • Spring Cloud DiscoveryClient 集成
  • 易于编写谓词和过滤器
  • 请求速率限制
  • 路径重写
    详情请参考官网添加链接描述
3.网关项目gulimall-gateway 3.1.pom文件


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.3.3.RELEASE
         
    

    com.atguigu.gulimall
    gulimall-gateway
    0.0.1-SNAPSHOT
    gulimall-gateway
    谷粒商城-API网关

    
        1.8
        Hoxton.SR7
    

    
        
            com.atguigu.gulimall
            gulimall-common
            0.0.1-SNAPSHOT
        
        
            org.springframework.cloud
            spring-cloud-starter-gateway
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


3.2注册到nacos

启动类上加**@EnableDiscoveryClient**,编辑配置文件application.properties

spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.application.name=gulimall-gateway
server.port=88
3.3.在nacos创建项目命名空间与配置



编辑bootstrap.properties

#bootstrap.properties优先于application.properties加载
#服务名
spring.application.name=gulimall-gateway

#注册中心地址
spring.cloud.nacos.config.server-addr=127.0.0.1:8848

#配置命名空间(默认是public空间,只能写唯一id不能写命名空间名称)
spring.cloud.nacos.config.namespace=e0d53e15-022c-466b-812f-c9e580552da0
4.启动项目错误分析与解决


原因:引入gulimall-common有mybatis-plus需要数据源相关信息
解决方案:在启动类上排除数据源

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/349216.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号