首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Swagger2 WebFlux小试牛刀

Swagger2 WebFlux小试牛刀

原创
作者头像
code4it
发布2019-04-10 23:09:08
4.3K0
发布2019-04-10 23:09:08
举报

本文主要展示一下如何使用支持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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • maven
  • 配置
  • 小结
  • doc
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档