Swagger2 WebFlux小试牛刀

本文主要展示一下如何使用支持WebFlux的Swagger

maven

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-webflux</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>
复制代码
  • swagger.version目前是3.0.0-SNAPSHOT,因而没有发布到maven官方仓库里头,需要从jcenter-snapshots中拉取
    <repositories>
        <repository>
            <id>jcenter-snapshots</id>
            <name>jcenter</name>
            <url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
        </repository>
    </repositories>
复制代码

配置

@Configuration
@EnableSwagger2WebFlux
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .description("example api")
                        .title("example api")
                        .version("1.0.0")
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.controller"))
                .paths(PathSelectors.any())
                .build();

    }
}
复制代码
  • 由于支持了WebFlux,所以之前的@EnableSwagger2就移除掉了,变为@EnableSwagger2WebMvc以及@EnableSwagger2WebFlux,这里使用的是@EnableSwagger2WebFlux

小结

  • Spring 5引入了WebFlux,而当前版本的SpringFox Swagger2(2.9.2)还不支持WebFlux,得使用3.0.0-SNAPSHOT才支持
  • 由于是SNAPSHOT版本,因而没有发布到maven官方仓库里头,需要从jcenter-snapshots中拉取,另外要使用支持WebFlux的Swagger2需要引入springfox-spring-webflux依赖
  • 由于支持了WebFlux,所以之前的@EnableSwagger2就移除掉了,变为@EnableSwagger2WebMvc以及@EnableSwagger2WebFlux

doc

转载于:https://juejin.im/post/5cae04a55188251acb52f9d4

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值