美文网首页
springboot + swagger2 集成配置

springboot + swagger2 集成配置

作者: mr_xl | 来源:发表于2018-08-03 15:39 被阅读0次

1.在pom.xml中添加依赖

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.4.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.4.0</version>
        </dependency>

2.添加加配置类

/**
 * @date 2018/7/25 下午 1:41
 * @details Swagger2配置类
 */
@Configuration
@EnableSwagger2
@Profile("dev")
public class Swagger2 {

    private static final String pageName = "项目包名";
    private static final String SWAGGER_TITLE = "系统所有API";
    private static final String SWAGGER_DESCRIBE = "可在本面板中查看/测试系统中所有API";

    /**
     * swagger2配置bean
     * @return Docker
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(pageName))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置信息
     * @return ApiInfo
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(SWAGGER_TITLE)
                .description(SWAGGER_DESCRIBE)
                .build();
    }
}

3.使用

例如:在controller 上加注解
    @ApiOperation(value = "根据视频设备id查询这个视频设备的信息")

相关文章

网友评论

      本文标题:springboot + swagger2 集成配置

      本文链接:https://www.haomeiwen.com/subject/gszyvftx.html