使用SpringCloudGateway

SOP默认网关是使用Spring Cloud Zuul,您也可以切换成Spring Cloud Gateway。

注::SOP对Spring Cloud Gateway的支持目前处于beta阶段,推荐使用zuul。

步骤如下:

  • 打开sop-gateway/pom.xml,注释spring cloud zuul依赖,打开Spring Cloud Gateway依赖
  1. <!-- ↓↓↓ 使用spring cloud zuul ↓↓↓
  2. <dependency>
  3. <groupId>org.springframework.cloud</groupId>
  4. <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
  5. </dependency>
  6. -->
  7. <!-- ↑↑↑ 使用spring cloud zuul ↑↑↑ -->
  8. <!-- ↓↓↓ 使用spring cloud gateway,处于beta阶段,推荐使用zuul ↓↓↓ -->
  9. <dependency>
  10. <groupId>org.springframework.cloud</groupId>
  11. <artifactId>spring-cloud-starter-gateway</artifactId>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.springframework.boot</groupId>
  15. <artifactId>spring-boot-starter-webflux</artifactId>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.springframework.boot</groupId>
  19. <artifactId>spring-boot-starter-actuator</artifactId>
  20. </dependency>
  21. <!-- ↑↑↑ 使用spring cloud gateway ↑↑↑ -->
  • 打开启动类SopGatewayApplication.java, 注释zuul相关注解
  1. package com.gitee.sop.gateway;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. //import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
  5. // 开启网关功能
  6. //@EnableZuulProxy
  7. @SpringBootApplication
  8. public class SopGatewayApplication {
  9. public static void main(String[] args) {
  10. SpringApplication.run(SopGatewayApplication.class, args);
  11. }
  12. }
  • 禁用ZuulConfig类,注释掉@Configuration注解即可
  1. //@Configuration
  2. public class ZuulConfig extends AlipayZuulConfiguration {
  • 启用GatewayConfig类,打开@Configuration注释
  1. @Configuration
  2. public class GatewayConfig extends AlipayGatewayConfiguration

修改完毕,重启sop-gateway

运行SpringCloudGatewayClientPostTest测试用例。