---
title: "spring-boot集成Springfox-Swagger2"
author: "lihao312"
date: "2016-10-12T21:47:25Z"
tags: ["Spring"]
categories: ["编程语言"]
slug: "spring-boot-springfox-swagger2"
draft: false
lastmod: "2016-10-12T21:54:10Z"
id: 2330205
url: "https://lihao312.iteye.com/blog/2330205"
---

# spring-boot-springfox

- [spring-boot](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/)
- [Springfox](http://springfox.github.io/springfox/)
- [Swagger](http://swagger.io/)

效果图：  
![](http://dl2.iteye.com/upload/attachment/0120/5829/9743ec81-375d-3a45-8c23-4fa6097fd14e.jpg)

```
<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](https://github.com/leelance/spring-boot-all/tree/master/spring-boot-springfox)