Files
SOP/doc/docs/files/10096_使用SpringCloudGateway.md
tanghc 36ee797ea6 2.0.0
2019-09-04 09:43:42 +08:00

93 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用SpringCloudGateway
SOP默认网关是使用Spring Cloud Zuul您也可以切换成Spring Cloud Gateway完整代码见`spring-cloud-gateway`分支。
如果您的系统并发量不大建议使用zuul因为zuul的功能更全面有新功能会优先实现在zuul上。
- SOP中 Spring Cloud Zuul 和 Spring Cloud Gateway功能对比
| 功能 | Spring Cloud Zuul | Spring Cloud Gateway |
| ----- | ---- | ----------------------- |
| 签名验证|√ | √ |
| 统一异常处理|√ | √ |
| 统一返回内容|√ | √ |
| session管理|√ | √ |
| 秘钥管理|√ | √ |
| 微服务端自动验证JSR-303|√ | √ |
| 文件上传|√ | √ |
| 文件下载|√ | √ |
| 接口限流|√ | √ |
| 文档整合|√ | √ |
| 应用授权|√ | √ |
| 监控日志|√ | √ |
| 支持nacos|√ | √ |
| 网关动态修改参数|√ | √ |
使用Spring Cloud Gateway步骤如下
- 打开sop-gateway/pom.xml注释spring cloud zuul依赖打开Spring Cloud Gateway依赖
```xml
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
-->
<!-- ↑↑↑ 使用spring cloud zuul ↑↑↑ -->
<!-- ↓↓↓ 使用spring cloud gateway处于beta阶段推荐使用zuul ↓↓↓ -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- ↑↑↑ 使用spring cloud gateway ↑↑↑ -->
```
- 打开启动类`SopGatewayApplication.java`, 注释zuul相关注解
```java
package com.gitee.sop.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
// 开启网关功能
//@EnableZuulProxy
@SpringBootApplication
public class SopGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(SopGatewayApplication.class, args);
}
}
```
- 禁用ZuulConfig类注释掉@Configuration注解即可
```java
//@Configuration
public class ZuulConfig extends AlipayZuulConfiguration {...}
```
- 启用GatewayConfig类打开@Configuration注释
```java
@Configuration
public class GatewayConfig extends AlipayGatewayConfiguration {...}
```
修改完毕重启sop-gateway