前言
找了一圈, 大家在Spring boot 2搭配Spring 5使用的时候。还是使用的Spring MVC的形式,没有直接上WebFlux的形式。正巧看到Springfox也发了快照版本支持WebFlux,今儿我就把这些整理一下。
使用工具和版本:
IntelliJ IDEA 2018.3.5 (Ultimate Edition)
JDK 1.8
Windows 10
Spring boot: 2.1.3.RELEASE
Springfox: 3.0.0.SNAPSHOT
上手
可以直接去start.spring.io快速构建一个程序,也可以看我的Github:link
一、POM
不去概述Swagger的作用了,直接上手。先在pom中引入以下依赖(需要先添加下Springfox快照所在的maven库)
1 | <dependencies> |
全部都使用3.0.0的快照版本,因为只有在当前版本支持了WebFlux,包含@EnableSwagger2WebFlux的注解。
二、配置
启用swagger,在main方法中添加@EnableSwagger2WebFlux
1 | 2WebFlux |
Configuration
创建一个Docketbean来配置Swagger,一个Docket实例为API配置提供默认设置和便捷的配置方法。
1 |
|
Controller
在Controller上就可以直接使用Swagger提供的注解了,但是不清楚现在是不是支持Webflux的Handler写法。
下面给了一个包含主要四个HTTP方法的Controller示例
1 |
|
视图
启动程序后,访问http://localhost:8080/swagger-ui.html/,看下页面显示

就是标准的Swagger-ui页面了,具体swagger使用方法可以去官网看看doc
引用
Spring Boot 2 RESTful API Documentation With Swagger 2 Tutorial
Springfox Reference Documentation
结束!🔚
