Swagger2介绍
Swagger是一款RESTful接口的文档在线自动生成、功能测试功能框架。一个规范和完整的框架,用于生成、描述、调用和可视化RESTful风格的Web服务,加上swagger-ui,可以有很好的呈现。

SpringBoot集成
这里选用的swagger版本为:2.8.0
- pom依赖
<!--swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
- 编写配置文件(Swagger2Config.java)
主要是添加注解@EnableSwagger2和定义Docket的bean类。
@Configuration
@EnableConfigurationProperties({ AuthCodeConfig.class })
@EnableSwagger2
publ

本文介绍了Swagger2作为RESTful接口文档在线生成和功能测试的框架,详细阐述了如何在SpringBoot项目中集成Swagger2,包括版本选择、pom依赖添加、Swagger2Config配置以及在Controller中添加注解。最后,通过访问`swagger-ui.html`来展示和使用生成的文档。
最低0.47元/天 解锁文章
667

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



