Chen Jian's Java Blog 

Code snippet: Swagger + Spring Boot

by Chen Jian


Posted on 2019-06-25 13:15 in Java


            compile 'io.springfox:springfox-swagger2:2.9.2'
            compile 'io.springfox:springfox-swagger-ui:2.9.2'

/**
 * See https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Value("${enable.swagger}")  //You may want to disabled it in PROD
    boolean enableSwagger;


    @Bean
    public Docket api() {
        Docket api = new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("your.package"))
                .paths(PathSelectors.any())
                .build();

        ApiInfo apiInfo = new ApiInfoBuilder()
                .version("xxx")
                .description("xxx")
                .termsOfServiceUrl("xxx")
                .title("Xxx Doc")
                .build();

        api.useDefaultResponseMessages(false).apiInfo(apiInfo);

        api.enable(enableSwagger);

        return api;
    }
}




No one has commented yet.
该日志评论功能被禁用了。