`
lihao312
  • 浏览: 479784 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

spring-boot集成Springfox-Swagger2

    博客分类:
  • java
阅读更多

spring-boot-springfox

效果图:

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

 


 

@Configuration  
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket adminApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("Admin API")
                .forCodeGeneration(true)
                .pathMapping("/")
                .select()
                .paths(paths())
                .build()
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(false);
    }

    private Predicate<String> paths(){
        return Predicates.and(PathSelectors.regex("/.*"), Predicates.not(PathSelectors.regex("/error")));
    }


    private ApiInfo apiInfo(){
        Contact contact = new Contact("lance", "https://github.com/leelance", "81222045@qq.com");
        return new ApiInfoBuilder()
                .title("Document Api")
                .description("Spring-boot-Springfox Example")
                .license("Apache License Version 2.0")
                .contact(contact)
                .version("2.0")
                .build();
    }
}

 

 项目完整路径:

 https://github.com/leelance/spring-boot-all/tree/master/spring-boot-springfox

 

 

  • 大小: 124.9 KB
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics