在SpringBoot2.x版本后,spring出了自己的Spring Cloud Gateway服务网关以替代停止开发进入维护的以及性能不算很好的Zuul。
(一)创建一个gateway-server服务网关子工程
新建工程后,在pom.xml文件中引入以下依赖:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<exclusions></exclusions>
</dependency>
</dependencies>
由于spring-cloud-starter-gateway依赖包含了spring-boot-starter-webflux
,由于web与webflux是不同的Web栈(可自行去了解),两者都存在的情况下,默认会选择web,假如不移除spring-boot-starter-web
依赖,则会报错:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoCon