Springboot集成swagger
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
配置Swagger基本信息,config包下:
@Configuration
@EnableSwagger2 //开启Swagger2
public class SwaggerConfig {
//配置Swagger的Docket的bean实例
@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo());
}
//配置Swagger信息
private ApiInfo apiInfo(){
//作者信息
Contact contact = new Contact("杨文杰","https://thinkerywj.github.io","744963774@qq.com");
return new ApiInfo("Api Documentation",
"Api Documentation",
"1.0",
"urn:tos",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList());
}
}
运行链接:http://localhost:8080/swagger-ui.html
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Lf2IPufX-1618837385547)(/images/Swagger/image-20210301140501253.png)]
本文介绍如何在SpringBoot项目中集成Swagger2,并提供详细的步骤。包括添加依赖、配置基本信息及扫描接口等,帮助快速实现API文档自动生成。
729

被折叠的 条评论
为什么被折叠?



