# webflux-root
**Repository Path**: tatic/webflux-root
## Basic Information
- **Project Name**: webflux-root
- **Description**: 基于webflux的springcloud脚手架
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 2
- **Created**: 2020-04-27
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# webflux-root
#### 介绍
基于webflux的springcloud脚手架
#### 为什么做这个东西
之前项目使用的是 2.0.x 的 springboot,springcloud 版本是 Finchley.M9。今天想把项目升级到springboot2.1.x,springcloud 版本升级到 Greenwich,然后把 zuul 替换成 gateway,发现 gateway 和 spring-boot-starter-web 包不兼容。同时,spring-boot-starter-web 包一般放在顶级模块中,如果把 spring-boot-starter-web 包注释掉,很多用 HttpServletRequest 等由spring-boot-starter-web 包提供的类做参数的 controller 也都不能用了,这就蛋疼了。所以长痛不如短痛,干脆把整个基于 spring-boot-starter-web 包的脚手架代码全部换成基于 spring-boot-starter-webflux 的,反正早晚得换。
做这个同时也是为了提供一个完整的从springboot2.0.x版本过渡到2.1.x版本的解决方案。
当然,如果你不想换掉 spring-boot-starter-web 包,也是可以的,只需要在gateway模块中引入 spring-boot-starter-webflux 包,然后把 spring-boot-starter-web 包排除掉就可以了。排除的方法是在gateway模块的pom.xml文件的dependencies中加入下面的配置即可
```xml
org.springframework.boot
spring-boot-starter-web
*
*
```
#### 模块结构和说明
经典的一父多子结构
webflux-root
├ webflux-rest
├ webflux-common
├ webflux-eureka
├ webflux-feign
└ webflux-gateway
- webflux-root:这个就不用多说了吧
- webflux-rest:基本的rest api接口(其实也就一个user下面挂几个接口),自带一个filter用于从jwt token中解析userId字段
- webflux-common:公共模块,什么公共类,工具类啥的
- webflux-eureka:就是springcloud的eureka,没别的
- webflux-feign:feignclient的测试程序
- webflux-gateway:这个是重头,提供路由,自定义全局过滤器,熔断等功能
#### 使用说明
1. 准备好你的postman,也就是接口调用工具
2. 本项目不需要数据库,redis,mq这些额外的东西
#### 如何体验
1. 用idea打开本项目,就是import webflux-root这个模块
2. 把能启动的都启动起来,可以使用idea的run dashboard,比较方便。建议先启动eureka
3. 使用postman先请求 user/login 接口,拿到一个jwt token。请求该接口需要将json字符串放入request body中发送,json字符串中必须含有id和name字段。示例json
{
"id":"1",
"name":"test",
"email":"test@1234.com"
}
4. 在调用需要传 jwt token 的接口时,如用POST方式去请求 /user/ 接口,需要在http头中设置 Authorization 属性,类型选Bearer Token,token就填调用 user/login 接口拿到的token。
5. 调用不需要传 jwt token 的接口时,不需要在 http 头中设置 Authorization 。
#### todo list
还有很多需要完善的地方
1. webflux-gateway中加入白名单功能
2. webflux-gateway中加入限流功能(支持自定义限流策略)
3. 其他有待发现的……
#### 如果你有更好的想法,请
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 参考资料
- [Spring5的WebFlux跟WebMvc对比]()
- [Spring WebFlux和Spring Cloud开发响应式微服务]()
- [WebFlux-Annotated Controllers]()
- [spring webflux(一)]()
- [Webflux快速入门]()
- [使用 Spring 5 的 WebFlux 开发反应式 Web 应用]()
- [Spring Cloud Gateway---自定义过滤器]()
- [Spring Cloud之Gateway(二):网关过滤器]()
- [spring cloud gateway集成hystrix全局断路器]()
- [spring cloud gateway 读取request body 数据]()
#### 问题日志
- 20190617:今天才发现,以前项目使用的druid数据库连接池还未支持webflux,而mysql目前也没有给出基于webflux的jdbc driver。所以目前使用mysql数据库作为持久层的应用,暂时无法升级到webflux。详见该帖
####