文
章
目
录
章
目
录
上一节我们讲了《Springboot集成Swagger2》,如果我们想要使用Swagger3版本,那么Springboot如何集成Swagger3呢?
其实非常相似,只需要修改几个小地方就可以了,建议大家可以先去查看下整合Swagger2的教程,在看本篇文章,接下来,潘老师就和大家说下具体的配置差异。
1、导入Swagger3依赖
在整合Swagger2时我们在pom.xml中导入了两个依赖,现在我们只需要导入1个依赖即可没具体如下:
<!--swagger3依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
2、修改Swagger2Config配置类
接下来,我们只需要修改下原先的Swagger2Config配置类中的部分就可以了,主要就是DocumentationType,而注解仍然是@EnableSwagger2不变,具体修改类似如下:
@Configuration // 配置类
@EnableSwagger2 // 开启 swagger2 的自动配置
public class Swagger2Config {
@Bean
public Docket docket() {
// 创建一个 swagger 的 bean 实例
return new Docket(DocumentationType.OAS_30)
// 配置基本信息
.apiInfo(apiInfo());
}
/**
* 基本信息设置
*/
private ApiInfo apiInfo() {
Contact contact = new Contact(
"潘子夜", // 作者姓名
"https://www.panziye.com", // 作者网址
"xxxxblog@126.com"); // 作者邮箱
return new ApiInfoBuilder()
.title("潘子夜博客-接口文档") // 标题
.description("专注分享编程技术") // 描述
.termsOfServiceUrl("https://hao.panziye.com") // 跳转连接
.version("1.0") // 版本
.license("Swagger教程")
.licenseUrl("https://www.panziye.com/back/9777.html")
.contact(contact)
.build();
}
}
3、查看swagger3文档效果
接下来,我们浏览器访问http://localhost:8080/swagger-ui/index.html
网址,查看下swagger3的文档效果,如下:
4、其他配置
其他的配置在此就不再赘述了,可以参考SpringBoot集成Swagger2的就行,两个其实没太大的差别。