首页 > 编程语言 > 详细

springboot整合swagger2

时间:2020-04-24 12:49:41      阅读:65      评论:0      收藏:0      [点我收藏+]

1.添加依赖(可能下载包的时候会遇到和其他包有冲突的问题,将版本降低就可以完美解决)

<!-- swagger依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>

 2..创建Swagger配置类:

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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("指向controller所在包的位置"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("SpringBoot利用Swagger构建API文档")
.description("使用RestFul风格")
.termsOfServiceUrl("链接")
.version("version 1.0")
.build();
}
}

 3.在启动类中加入@EnableSwagger2注解

访问路径:http://localhost:端口号/服务名/swagger-ui.html#/

技术分享图片

 

springboot整合swagger2

原文:https://www.cnblogs.com/maoxy/p/12766511.html

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