码迷,mamicode.com
首页 > 编程语言 > 详细

Spring boot 配置 swagger

时间:2017-07-17 22:12:03      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:private   host   htm   使用说明   div   访问   blog   restful   control   

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/

Spring boot 配置 swagger

标签:private   host   htm   使用说明   div   访问   blog   restful   control   

原文地址:http://www.cnblogs.com/rufus-hua/p/7197379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!