Spring boot 配置 swagger

1、maven配置包

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.7.0</version>
</dependency>

2、配置类

@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo")) //这里改成你报controller报名即可
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {

        return new ApiInfoBuilder()
                .title("RESTful APIs")
                .description("RESTFul API 文档")
                .version("1.0")
                .build();
    }
}

3、访问地址: http://localhost:8080/swagger-ui.html

 

官方使用说明:http://springfox.github.io/springfox/docs/current/

posted @ 2017-07-17 20:26  沐松  阅读(451)  评论(0编辑  收藏  举报