【springCloud搭建】三、集成springCloudGateway网关
上篇文章传送门:【springCloud搭建】二、集成nacos微服务注册中心
springCloudGateway的过滤器和拦截器的使用传送门:
springCloudGateway 网关服务模块所需第三方包的pom展示,注意gateway的pom不能继承cloud_demo的pom,否则会启动不起来
<?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"><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.13.RELEASE</version><relativePath/></parent><modelVersion>4.0.0</modelVersion><groupId>org.wcy</groupId><artifactId>gateway</artifactId><version>1.0.0</version><name>gateway</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><junit.version>4.11</junit.version><cloud-alibaba.version>2.1.4.RELEASE</cloud-alibaba.version><cloud.version>Greenwich.SR6</cloud.version></properties><dependencyManagement><dependencies><!-- cloud-alibaba全家桶--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${cloud-alibaba.version}</version><type>pom</type><scope>import</scope></dependency><!-- cloud全家桶--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>${junit.version}</version><scope>test</scope></dependency><!--gateway网关模块--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><!--nacos注册中心--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!--alibaba服务监控组件--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId></dependency></dependencies><build><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.1.3.RELEASE</version></plugin></plugins></pluginManagement><plugins><!-- 编译插件(设置源代码的JDK版本,目标代码JDK版本,编译字符集) --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version><configuration><source>8</source><target>8</target><encoding>UTF-8</encoding></configuration></plugin></plugins><resources><resource><directory>src/main/java</directory><includes><include>**/*Mapper.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/resources</directory><includes><!--包含resources文件夹以及子文件夹下所有资源--><include>**/*.*</include></includes></resource></resources></build>
</project>
配置文件
server:port: 8888tomcat:uri-encoding: UTF-8
spring:application:name: gatewaycloud:gateway:discovery:locator:enabled: true #开启从注册中心动态创建路由的功能,利用微服务名进行路由nacos:discovery:#nacos集群地址多个以,分隔server-addr: 192.168.31.91:9949,192.168.31.91:9948http:encoding:charset: UTF-8enabled: trueforce: true
启动类
package org.wcy;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;/*** <p>Title : GatewayApplication.java</p>* <p>Description : 网关服务模块启动类</p>* <p>DevelopTools : IntelliJ IDEA 2018.2.3 x64</p>* <p>DevelopSystem : Windows 10</p>* <p>Company : org.wcy</p>* @author : WangChenYang* @date : 2021/5/15 20:13* @version : 0.0.1*/
@SpringBootApplication
/*注册到nacos*/
@EnableDiscoveryClient
public class GatewayApplication {public static void main(String[] args) {SpringApplication.run(GatewayApplication.class, args);}}
启动成功后我们就可以看到gateway已经注册到nacos上了,后面的请求路由都是根据gateway来的,我们配置的根据服务名来路由
下篇传送门:【springCloud搭建】四、集成ribbon+hystrix+feign
【springCloud搭建】三、集成springCloudGateway网关相关推荐
- SpringCloud→SpringCloud搭建Zuul动态服务网关(五)
文章目录 SpringCloud搭建Zuul动态服务网关 网关分类 开放Api 微服务网关 API服务管理平台 网关设计 开放API接口 内网API接口 网关框架 使用Zuul实现反向代理 使用Zuu ...
- 【springCloud搭建】四、集成ribbon+hystrix+feign
上篇文章传送门:[springCloud搭建]三.集成springCloudGateway网关 ribbon+hystrix+feign所需的第三方包 <!--feign服务通讯组件--> ...
- 【springCloud搭建】六、集成RabbitMQ
上篇文章传送门:[springCloud搭建]五.集成mybatis-plus 一.所需jar包 <spring-boot.version>2.3.0.RELEASE</spring ...
- sentinel接入网关应用_微服务初体验(三):集成Gateway网关和Sentinel限流
前言 最近笔者在对微服务架构进行学习,参考了各种项目的技术文章.框架文档以及视频网站,最终选择使用Nacos+Dubbo+Gateway+Sentinel来搭建一个项目练手.其中Nacos作为服务的注 ...
- 【springCloud搭建】五、集成mybatis-plus
上篇文章传送门:[springCloud搭建]四.集成ribbon+hystrix+feign 将mybatis-plus所需第三方包加入cloud_demo的pom.xml内 <mybatis ...
- 【SpringCloud深入浅出系列】SpringCloud组件之集成Zuul实现过滤器
目录 一.Zuul 路由和过滤 二.Zuul 过滤器类型 (一)标准过滤器 1.pre 2.routing 3.post 4.error (二)特殊过滤器 1.StaticResponseFilter ...
- SpringCloud搭建
1.1 spring boot简介: Spring cloud 基于spring boot 去构建, 所以先介绍下 spring boot. Spring框架功能很强大,但是就算是一个很简单的项目,我 ...
- springcloud搭建篇
springcloud微服务 微服务:拆分.单一.独立.组件化.将一个复杂的庞大的项目拆分成一个一个的小项目独立的运行,通过接口的方式组装成一个大项目. springcloud是基于springboo ...
- springcloud feign 服务调用其他服务_微服务实战——SpringCloud与Feign集成
上一篇集成了ZuulGateway和Eureka并进行了测试.在实际场景中,我们肯定会有很多的微服务,而他们之间可能会存在相互调用的关系,那么,如何优雅的处理服务之间的调用问题呢?接下来就是我们要解决 ...
最新文章
- Dynamics AX 2009 升级PreSynchnoize时的无反应的解决
- CI框架常用函数(AR数据库操作的常用函数)
- AI智能手机会是什么样?至少有这十个功能
- 一、如何创建一个状态栏扩展(火狐插件扩展开发教程)
- TF之NN:利用神经网络系统自动学习散点(二次函数+noise+优化修正)输出结果可视化(matplotlib动态演示)
- 乐在其中设计模式(C#) - 提供者模式(Provider Pattern)
- MATLAB数据分析3
- easyphp环境配置
- influxdb删除某一列(tag或者field)
- centos和redhat vsftp安装和设定
- 构造方法传参数的小心得
- Linux(Centos)服务器时间校准
- 轻松处理PHP开发中微信emoji表情mysql存储的问题
- 小程序UI框架推荐:Vant让你优雅的飞
- Exynos4412 移植Linux Kernel 5.4过程记录(三)——根文件系统构建与SD卡挂载fs
- 影视后期制作学习第四天(AE)
- android视频编辑好,安卓比较好用的视频剪辑软件 手机视频剪辑软件推荐
- 关于密码复杂度至少8位,包含大写字母、小写字母、数字、特殊字符中至少3种组合的正则
- Problem B. 涮羊肉
- 手机如何拍出中背景模糊虚化的拍摄技巧
热门文章
- 云开发初探 —— 更简便的小程序开发模式 1
- 51单片机 跑步机控制器设计
- TLA+概述--Summary of TLA+
- select vba 网页 翻页_Excel 如何利用VBA实现快捷翻页功能?
- 一种RuntimeError Key bert/embeddings/position_embeddings not found in checkpoint的解决思路
- 神奇代码岛box.fun(https://box3.codemao.cn/?from=cmsqfilter=common)
- 【微信小程序原生】 封装request
- cad开发 php,什么叫cad软件
- 英文心灵鸡汤小记-2
- Android 单元测试,从小白到入门开始