springboot整合Swagger

2019-03-31  本文已影响0人  泥煤的嘎嘎
<!--swagger-->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.8.0</version>
</dependency>
<!--swagger UI-->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.8.0</version>
</dependency>
/**
 * swagger config
 *
 * @author 伍磊
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //扫描的是自定义Controller的包名 (与下面二选其一  建议单工程下选择扫描包,多工程下选择扫描注解)
                .apis(RequestHandlerSelectors.basePackage("com.leiwu.train"))
                // 扫描@ApiOperation注解
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .build();
    }
}

Swagger-ui的坑-接口无法展开

上一篇 下一篇

猜你喜欢

热点阅读