首页 > 编程语言 > 详细

springboot整合swagger

时间:2019-09-20 13:07:58      阅读:137      评论:0      收藏:0      [点我收藏+]

这里我就省略了springboot框架的搭建,进行直接整合swagger

在你的springboot框架的启动类的同一级目录下,新建一个包config,在包下,新建一个类Swagger2Config,如图:

技术分享图片

 

 

 Swagger2Config类内容:

package com.wangtong.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@Configuration
public class Swagger2Config {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //为自己项目中的controller包路径
                .apis(RequestHandlerSelectors.basePackage("com.wangtong.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    //构建 api文档的详细信息函数
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("Spring Boot集成Swagger2构建RESTful API")
                //创建人信息
                .contact(new Contact("Eric", "http://www.nyist.edu.cn", "Eric@163.com"))
                //版本号
                .version("1.9")
                //描述
                .description("演示系统API描述")
                .build();
    }
}

之后启动自己的springboot框架,访问swagger路径:

技术分享图片

 

 出现这个页面,代表测试成功!

 

springboot整合swagger

原文:https://www.cnblogs.com/BeenTogether/p/11556035.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!