1.引入依赖(使用的3.0版本,与2.x的版本有所区别)
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
2.编写swagger配置类
@Configuration
@EnableSwagger2
public class SwaggerConfig {
//创建一个Docket的对象,相当于是swagger的一个实例
@Bean
public Docket docket(){
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo());
}
//配置相关的api信息
private ApiInfo apiInfo(){
Contact contact=new Contact("yzy","https://www.cnblogs.com/shouyaya/","1255014278@qq.com");
return new ApiInfo(
"yzy的swaggerAPI文档",
"第一个swagger程序",
"1.0",
"urn:tos",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList<>());
}
}
3.启动应用!访问swagger页面
注意:
- 这次更新,移除了原来默认的swagger页面路径:
http://host/context-path/swagger-ui.html
,新增了两个可访问路径:http://host/context-path/swagger-ui/index.html
和http://host/context-path/swagger-ui/
- 通过调整日志级别,还可以看到新版本的swagger文档接口也有新增,除了以前老版本的文档接口
/v2/api-docs
之外,还多了一个新版本的/v3/api-docs
接口。
来源:oschina
链接:https://my.oschina.net/u/4269975/blog/4480629